Class: Monkeyshines::Store::KeyStore
- Defined in:
- lib/wukong/store/key_store.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#db ⇒ Object
The actual backing store; should respond to #set and #get methods.
Class Method Summary collapse
-
.new_from_command_line(cmdline_opts, default_opts = {}) ⇒ Object
Load from standard command-line options.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #close ⇒ Object
-
#each(&block) ⇒ Object
Executes block once for each element in the whole DB, in whatever order the DB thinks you should see it.
- #get(key) ⇒ Object
-
#set(key, val) ⇒ Object
(also: #save)
Save the value into the database.
- #size ⇒ Object
Instance Attribute Details
#db ⇒ Object
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={} = default_opts.merge(cmdline_opts) store = self.new([:store_db]) store end |
Instance Method Details
#[](key) ⇒ Object
35 |
# File 'lib/wukong/store/key_store.rb', line 35 def [](key) db[key] end |
#close ⇒ Object
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 |
#size ⇒ Object
37 |
# File 'lib/wukong/store/key_store.rb', line 37 def size() db.size end |