Class: Docket::Storage
- Inherits:
-
Object
- Object
- Docket::Storage
- Defined in:
- lib/docket/storage.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
Returns the value of attribute db.
Instance Method Summary collapse
- #append(key, value) ⇒ Object
- #append_to_group(group, value) ⇒ Object
- #close ⇒ Object
-
#initialize(filename) ⇒ Storage
constructor
A new instance of Storage.
- #load ⇒ Object
- #read(key) ⇒ Object
- #save(key, value, options = {}) ⇒ Object
Constructor Details
#initialize(filename) ⇒ Storage
Returns a new instance of Storage.
8 9 10 |
# File 'lib/docket/storage.rb', line 8 def initialize filename @db = Daybreak::DB.new filename end |
Instance Attribute Details
#db ⇒ Object
Returns the value of attribute db.
6 7 8 |
# File 'lib/docket/storage.rb', line 6 def db @db end |
Instance Method Details
#append(key, value) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/docket/storage.rb', line 22 def append key, value touch do new_value = Array(read(key)) << value save(key, new_value) end end |
#append_to_group(group, value) ⇒ Object
41 42 43 |
# File 'lib/docket/storage.rb', line 41 def append_to_group group, value append group, value end |
#close ⇒ Object
37 38 39 |
# File 'lib/docket/storage.rb', line 37 def close db.close end |
#load ⇒ Object
33 34 35 |
# File 'lib/docket/storage.rb', line 33 def load db.load end |
#read(key) ⇒ Object
29 30 31 |
# File 'lib/docket/storage.rb', line 29 def read key touch { db.get key } end |
#save(key, value, options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/docket/storage.rb', line 12 def save key, value, ={} touch do append_to_group([:group], key) if [:group] db.set! key, value db.compact db.flush end end |