Class: AnyStyle::Dictionary::LMDB
Instance Attribute Summary collapse
#db, #options
Instance Method Summary
collapse
create, instance, #populate!, #tag_counts, #tags
Constructor Details
#initialize(options = {}) ⇒ LMDB
Returns a new instance of LMDB.
15
16
17
|
# File 'lib/anystyle/dictionary/lmdb.rb', line 15
def initialize(options = {})
super(self.class.defaults.merge(options))
end
|
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
13
14
15
|
# File 'lib/anystyle/dictionary/lmdb.rb', line 13
def env
@env
end
|
Instance Method Details
#close ⇒ Object
30
31
32
|
# File 'lib/anystyle/dictionary/lmdb.rb', line 30
def close
env.close if open?
end
|
#empty? ⇒ Boolean
38
39
40
|
# File 'lib/anystyle/dictionary/lmdb.rb', line 38
def empty?
open? and db.size == 0
end
|
#get(key) ⇒ Object
50
51
52
|
# File 'lib/anystyle/dictionary/lmdb.rb', line 50
def get(key)
db[key.to_s].to_i
end
|
#lmdb_options ⇒ Object
62
63
64
|
# File 'lib/anystyle/dictionary/lmdb.rb', line 62
def lmdb_options
options.reject { |k| [:path, :source].include?(k) }
end
|
#open ⇒ Object
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/anystyle/dictionary/lmdb.rb', line 19
def open
unless open?
@env = ::LMDB.new(path, lmdb_options)
@db = @env.database create: true
end
self
ensure
populate! if empty?
end
|
#open? ⇒ Boolean
34
35
36
|
# File 'lib/anystyle/dictionary/lmdb.rb', line 34
def open?
!db.nil?
end
|
#path ⇒ Object
58
59
60
|
# File 'lib/anystyle/dictionary/lmdb.rb', line 58
def path
options[:path]
end
|
#put(key, value) ⇒ Object
54
55
56
|
# File 'lib/anystyle/dictionary/lmdb.rb', line 54
def put(key, value)
db[key.to_s] = value.to_i.to_s
end
|
#truncate ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/anystyle/dictionary/lmdb.rb', line 42
def truncate
close
%w{ data.mdb lock.mdb }.each do |mdb|
mdb = File.join(path, mdb)
File.unlink(mdb) if File.exists?(mdb)
end
end
|