Class: Gulp::DataStore
- Inherits:
-
Object
- Object
- Gulp::DataStore
- Includes:
- Enumerable, TokyoCabinet
- Defined in:
- lib/gulp/data_store.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #clear! ⇒ Object
- #each(&proc) ⇒ Object
- #each_key(&proc) ⇒ Object
- #has_key?(key) ⇒ Boolean
- #increment(key) ⇒ Object
-
#initialize(path) ⇒ DataStore
constructor
A new instance of DataStore.
- #size ⇒ Object
Constructor Details
#initialize(path) ⇒ DataStore
Returns a new instance of DataStore.
6 7 8 9 |
# File 'lib/gulp/data_store.rb', line 6 def initialize(path) @hdb = HDB::new @hdb.open(path + '.hdb', HDB::OWRITER | HDB::OCREAT) end |
Instance Method Details
#[](key) ⇒ Object
15 16 17 18 |
# File 'lib/gulp/data_store.rb', line 15 def [](key) val = @hdb[key] val ? val.unpack('i').first : 0 end |
#[]=(key, value) ⇒ Object
20 21 22 |
# File 'lib/gulp/data_store.rb', line 20 def []=(key, value) @hdb[key] = value end |
#clear! ⇒ Object
28 29 30 |
# File 'lib/gulp/data_store.rb', line 28 def clear! @hdb.vanish end |
#each(&proc) ⇒ Object
39 40 41 |
# File 'lib/gulp/data_store.rb', line 39 def each(&proc) @hdb.each(&proc) end |
#each_key(&proc) ⇒ Object
36 37 38 |
# File 'lib/gulp/data_store.rb', line 36 def each_key(&proc) @hdb.each_key(&proc) end |
#has_key?(key) ⇒ Boolean
24 25 26 |
# File 'lib/gulp/data_store.rb', line 24 def has_key?(key) @hdb[key].present? end |
#increment(key) ⇒ Object
11 12 13 |
# File 'lib/gulp/data_store.rb', line 11 def increment(key) @hdb.addint(key,1) end |
#size ⇒ Object
32 33 34 |
# File 'lib/gulp/data_store.rb', line 32 def size @hdb.rnum end |