Class: Monkeyshines::Store::KeyStore

Inherits:
Base
  • Object
show all
Defined in:
lib/wukong/store/key_store.rb

Direct Known Subclasses

TokyoTdbKeyStore

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dbObject

The actual backing store; should respond to #set and #get methods



5
6
7
# File 'lib/wukong/store/key_store.rb', line 5

def db
  @db
end

Class Method Details

.new_from_command_line(cmdline_opts, default_opts = {}) ⇒ Object

Load from standard command-line options

obvs only works when there’s just one store



44
45
46
47
48
# File 'lib/wukong/store/key_store.rb', line 44

def self.new_from_command_line cmdline_opts, default_opts={}
  options = default_opts.merge(cmdline_opts)
  store = self.new(options[:store_db])
  store
end

Instance Method Details

#[](key) ⇒ Object



35
# File 'lib/wukong/store/key_store.rb', line 35

def [](key)       db[key]  end

#closeObject



36
# File 'lib/wukong/store/key_store.rb', line 36

def close()       db.close end

#each(&block) ⇒ Object

Executes block once for each element in the whole DB, in whatever order the DB thinks you should see it.

Your block will see |key, val|

key_store.each do |key, val|

# ... stuff ...

end



17
18
19
20
21
22
23
24
# File 'lib/wukong/store/key_store.rb', line 17

def each &block
  db.iterinit
  loop do
    key = db.iternext or break
    val = db[key]
    yield key, val
  end
end

#get(key) ⇒ Object



34
# File 'lib/wukong/store/key_store.rb', line 34

def get(key)      db[key]  end

#set(key, val) ⇒ Object Also known as: save

Save the value into the database



28
29
30
31
# File 'lib/wukong/store/key_store.rb', line 28

def set(key, val)
  return unless val
  db[key] = val
end

#sizeObject



37
# File 'lib/wukong/store/key_store.rb', line 37

def size()        db.size  end