Module: Persist::KCAdapter
- Includes:
- TSVAdapter
- Defined in:
- lib/rbbt/persist/tsv/kyotocabinet.rb
Constant Summary
Constants included
from TSVAdapter
TSVAdapter::MAX_CHAR
Instance Attribute Summary collapse
Attributes included from TSVAdapter
#closed, #mutex, #persistence_path, #writable
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from TSVAdapter
#closed?, #get_prefix, #merge!, #prefix, #range, #read?, #read_and_close, #write_and_close, #write_and_read
Instance Attribute Details
#kyotocabinet_class ⇒ Object
Returns the value of attribute kyotocabinet_class.
7
8
9
|
# File 'lib/rbbt/persist/tsv/kyotocabinet.rb', line 7
def kyotocabinet_class
@kyotocabinet_class
end
|
Class Method Details
.open(path, write, kyotocabinet_class = "kch") ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/rbbt/persist/tsv/kyotocabinet.rb', line 9
def self.open(path, write, kyotocabinet_class = "kch")
real_path = path + ".#{kyotocabinet_class}"
@persistence_path = real_path
flags = (write ? KyotoCabinet::DB::OWRITER | KyotoCabinet::DB::OCREATE : nil)
database =
CONNECTIONS[path] ||= begin
db = KyotoCabinet::DB.new
db.open(real_path, flags)
db
end
database.extend KCAdapter
database.persistence_path ||= real_path
database
end
|
Instance Method Details
#close ⇒ Object
28
29
30
31
32
|
# File 'lib/rbbt/persist/tsv/kyotocabinet.rb', line 28
def close
@closed = true
super
self
end
|
#collect ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/rbbt/persist/tsv/kyotocabinet.rb', line 62
def collect
res = []
each do |key, value|
res << if block_given?
yield key, value
else
[key, value]
end
end
res
end
|
#delete(key) ⇒ Object
74
75
76
|
# File 'lib/rbbt/persist/tsv/kyotocabinet.rb', line 74
def delete(key)
out(key)
end
|
#read(force = false) ⇒ Object
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/rbbt/persist/tsv/kyotocabinet.rb', line 34
def read(force = false)
return if not write? and not closed and not force
self.close
if !self.open(@persistence_path, KyotoCabinet::DB::OREADER)
raise "Open error #{ res }. Trying to open file #{@persistence_path}"
end
@writable = false
@closed = false
self
end
|
#write(force = true) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/rbbt/persist/tsv/kyotocabinet.rb', line 45
def write(force = true)
return if write? and not closed and not force
self.close
if !self.open(@persistence_path, KyotoCabinet::DB::OWRITER)
raise "Open error. Trying to open file #{@persistence_path}"
end
@writable = true
@closed = false
self
end
|
#write? ⇒ Boolean
58
59
60
|
# File 'lib/rbbt/persist/tsv/kyotocabinet.rb', line 58
def write?
@writable
end
|