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



20
21
22
23
24
25
# File 'lib/docket/storage.rb', line 20

def append key, value
  touch do
    new_value = Array(read(key)) << value
    save(key, new_value.uniq)
  end
end

#closeObject



39
40
41
# File 'lib/docket/storage.rb', line 39

def close
  db.close
end

#loadObject



35
36
37
# File 'lib/docket/storage.rb', line 35

def load
  db.load
end

#read(key) ⇒ Object



31
32
33
# File 'lib/docket/storage.rb', line 31

def read key
  touch { db.get key }
end

#remove(key) ⇒ Object



27
28
29
# File 'lib/docket/storage.rb', line 27

def remove key
  touch { db.delete! key }
end

#save(key, value, options = {}) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/docket/storage.rb', line 12

def save key, value, options={}
  touch do
    db.set! key, value
    db.compact
    db.flush
  end
end