Module: Persist::FWTAdapter
- Includes:
- TSVAdapter
- Defined in:
- lib/rbbt/persist/tsv/fix_width_table.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
#close, #closed?, #collect, #delete, #get_prefix, #merge!, #prefix, #range, #read?, #read_and_close, #write?, #write_and_close, #write_and_read
Instance Attribute Details
#pos_function ⇒ Object
Returns the value of attribute pos_function.
8
9
10
|
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 8
def pos_function
@pos_function
end
|
Class Method Details
.open(path, value_size, range = false, update = false, in_memory = false, &pos_function) ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 10
def self.open(path, value_size, range = false, update = false, in_memory = false, &pos_function)
db = CONNECTIONS[path] ||= FixWidthTable.new(path, value_size, range, update, in_memory)
db.extend Persist::FWTAdapter
db.persistence_path = path
db.pos_function = pos_function
db
end
|
Instance Method Details
#<<(key, value) ⇒ Object
73
74
75
|
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 73
def <<(key, value)
self.send(:[]=, *i)
end
|
#[](key) ⇒ Object
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 40
def [](key)
if TSV::ENTRY_KEYS.include? key
metadata[key]
else
key = pos_function.call(key) if pos_function
res = super(key)
res.extend MultipleResult
res
end
end
|
#[]=(key, value) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 51
def []=(key, value)
if TSV::ENTRY_KEYS.include? key
set_metadata(key, value)
else
if range
add_range_point key, value
else
add key, value
end
end
end
|
#add(key, value) ⇒ Object
63
64
65
66
|
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 63
def add(key, value)
key = pos_function.call(key) if pos_function and not (range and Array === key)
super(key, value)
end
|
#add_range_point(key, value) ⇒ Object
68
69
70
71
|
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 68
def add_range_point(key, value)
key = pos_function.call(key) if pos_function
super(key, value)
end
|
#each ⇒ Object
87
88
89
90
91
|
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 87
def each
@size.times do |i|
yield i, value(i)
end
end
|
#include?(i) ⇒ Boolean
77
78
79
80
81
|
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 77
def include?(i)
return true if Fixnum === i and i < pos(@size)
return true if metadata.include? i
false
end
|
#keys ⇒ Object
93
94
95
|
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 93
def keys
[]
end
|
27
28
29
30
31
32
|
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 27
def metadata
return {} unless File.exists? metadata_file
Open.open(metadata_file, :mode => "rb") do |f|
Marshal.load(f)
end
end
|
23
24
25
|
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 23
def metadata_file
@metadata_file ||= self.persistence_path + '.metadata'
end
|
#persistence_path=(value) ⇒ Object
18
19
20
21
|
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 18
def persistence_path=(value)
@persistence_path = value
@filename = value
end
|
34
35
36
37
38
|
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 34
def set_metadata(k,v)
metadata = self.metadata
metadata[k] = v
Misc.sensiblewrite(metadata_file, Marshal.dump(metadata))
end
|
#size ⇒ Object
83
84
85
|
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 83
def size
@size
end
|