Class: Monkeyshines::Store::TokyoTdbKeyStore
- Defined in:
- lib/wukong/store/tokyo_tdb_key_store.rb
Overview
Implementation of KeyStore with a Local TokyoCabinet table database (TDB)
Instance Attribute Summary
Attributes inherited from KeyStore
Instance Method Summary collapse
- #each_as(klass, &block) ⇒ Object
-
#initialize(db_uri, *args) ⇒ TokyoTdbKeyStore
constructor
pass in the filename or URI of a tokyo cabinet table-style DB set create_db = true if you want to create a missing DB file.
-
#set(key, val) ⇒ Object
Delegate to store.
- #size ⇒ Object
Methods inherited from KeyStore
#[], #close, #each, #get, new_from_command_line
Constructor Details
#initialize(db_uri, *args) ⇒ TokyoTdbKeyStore
pass in the filename or URI of a tokyo cabinet table-style DB set create_db = true if you want to create a missing DB file
11 12 13 14 15 |
# File 'lib/wukong/store/tokyo_tdb_key_store.rb', line 11 def initialize db_uri, *args self.db = TokyoCabinet::TDB.new db.open(db_uri, TokyoCabinet::TDB::OWRITER) or raise "#{self.class.to_s}: Can't open TokyoCabinet TDB #{db_uri}" super *args end |
Instance Method Details
#each_as(klass, &block) ⇒ Object
18 19 20 21 22 |
# File 'lib/wukong/store/tokyo_tdb_key_store.rb', line 18 def each_as klass, &block self.each do |key, hsh| yield klass.from_hash hsh end end |
#set(key, val) ⇒ Object
Delegate to store
24 25 26 27 |
# File 'lib/wukong/store/tokyo_tdb_key_store.rb', line 24 def set(key, val) return unless val db.put key, val.to_hash.compact end |
#size ⇒ Object
29 |
# File 'lib/wukong/store/tokyo_tdb_key_store.rb', line 29 def size() db.rnum end |