Class: AnyStyle::Dictionary::GDBM
Instance Attribute Summary collapse
#db, #options
Instance Method Summary
collapse
create, instance, #populate!, #tag_counts, #tags
Constructor Details
#initialize(options = {}) ⇒ GDBM
Returns a new instance of GDBM.
14
15
16
|
# File 'lib/anystyle/dictionary/gdbm.rb', line 14
def initialize(options = {})
super(self.class.defaults.merge(options))
end
|
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
12
13
14
|
# File 'lib/anystyle/dictionary/gdbm.rb', line 12
def env
@env
end
|
Instance Method Details
#close ⇒ Object
26
27
28
|
# File 'lib/anystyle/dictionary/gdbm.rb', line 26
def close
db.close if open?
end
|
#empty? ⇒ Boolean
34
35
36
|
# File 'lib/anystyle/dictionary/gdbm.rb', line 34
def empty?
open? and db.empty?
end
|
#get(key) ⇒ Object
43
44
45
|
# File 'lib/anystyle/dictionary/gdbm.rb', line 43
def get(key)
db[key.to_s].to_i
end
|
#open ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/anystyle/dictionary/gdbm.rb', line 18
def open
close
@db = ::GDBM.new(*options.values_at(:path, :mode, :flags))
self
ensure
populate! if empty?
end
|
#open? ⇒ Boolean
30
31
32
|
# File 'lib/anystyle/dictionary/gdbm.rb', line 30
def open?
!(db.nil? || db.closed?)
end
|
#put(key, value) ⇒ Object
47
48
49
|
# File 'lib/anystyle/dictionary/gdbm.rb', line 47
def put(key, value)
db[key.to_s] = value.to_i.to_s
end
|
#truncate ⇒ Object
38
39
40
41
|
# File 'lib/anystyle/dictionary/gdbm.rb', line 38
def truncate
close
File.unlink(options[:path])
end
|