Class: Docket::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/docket/storage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dbObject

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

#closeObject



37
38
39
# File 'lib/docket/storage.rb', line 37

def close
  db.close
end

#loadObject



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, options={}
  touch do
    append_to_group(options[:group], key) if options[:group]

    db.set! key, value
    db.compact
    db.flush
  end
end