M000202.html

tmud-2.10.0/doc/classes/GdbmStore.src/M000202.html · 2.6 KB

From the archive tmud-2.10.0.tar.gz

Download the archive   « Back to the archive contents

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>new (GdbmStore)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre><span class="ruby-comment cmt"># File lib/storage/gdbmstore.rb, line 29</span>
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">dbfile</span>)
    <span class="ruby-keyword kw">super</span>()
    <span class="ruby-ivar">@dbfile</span> = <span class="ruby-node">&quot;#{dbfile}.gdbm&quot;</span>

    <span class="ruby-comment cmt"># check if database exists and build it if not</span>
    <span class="ruby-identifier">build_database</span>
    <span class="ruby-identifier">log</span>.<span class="ruby-identifier">info</span> <span class="ruby-value str">&quot;Loading world...&quot;</span>

    <span class="ruby-comment cmt"># open database and sets @dbtop to highest object id</span>
    <span class="ruby-ivar">@db</span> = <span class="ruby-constant">GDBM</span>.<span class="ruby-identifier">open</span>(<span class="ruby-ivar">@dbfile</span>, <span class="ruby-value">0666</span>)
    <span class="ruby-ivar">@db</span>.<span class="ruby-identifier">each_key</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">o</span><span class="ruby-operator">|</span>
      <span class="ruby-ivar">@dbtop</span> = <span class="ruby-identifier">o</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@dbtop</span>
    <span class="ruby-keyword kw">end</span>

    <span class="ruby-ivar">@cache</span> = <span class="ruby-constant">CacheManager</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@db</span>)
    <span class="ruby-identifier">log</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">&quot;Database '#{@dbfile}' loaded...highest id = #{@dbtop}.&quot;</span>
<span class="ruby-comment cmt">#    log.debug @db.inspect</span>
  <span class="ruby-keyword kw">rescue</span>
    <span class="ruby-identifier">log</span>.<span class="ruby-identifier">fatal</span> <span class="ruby-identifier">$!</span>
    <span class="ruby-identifier">raise</span>
  <span class="ruby-keyword kw">end</span></pre>
</body>
</html>

Site Stats

Snippets: 1791
Codebases: 571