Module: Imba::DataStore
- Defined in:
- lib/imba/data_store.rb
Class Attribute Summary collapse
-
.data ⇒ Object
readonly
Returns the value of attribute data.
- .path ⇒ Object
Class Method Summary collapse
- .[](key) ⇒ Object
- .[]=(key, value) ⇒ Object
- .all ⇒ Object
- .clear ⇒ Object
- .data_store ⇒ Object
- .delete(*keys) ⇒ Object
- .init ⇒ Object
- .inspect ⇒ Object
- .key?(key) ⇒ Boolean
- .to_a ⇒ Object
- .to_hash ⇒ Object
- .transaction ⇒ Object
Class Attribute Details
.data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/imba/data_store.rb', line 6 def data @data end |
Class Method Details
.[](key) ⇒ Object
24 25 26 |
# File 'lib/imba/data_store.rb', line 24 def [](key) data_store.transaction(true) { @data[key] } end |
.[]=(key, value) ⇒ Object
28 29 30 |
# File 'lib/imba/data_store.rb', line 28 def []=(key, value) data_store.transaction { @data[key] = value } end |
.all ⇒ Object
32 33 34 |
# File 'lib/imba/data_store.rb', line 32 def all data_store.transaction(true) { @data.roots } end |
.clear ⇒ Object
62 63 64 |
# File 'lib/imba/data_store.rb', line 62 def clear delete(all) end |
.data_store ⇒ Object
20 21 22 |
# File 'lib/imba/data_store.rb', line 20 def data_store data || init end |
.delete(*keys) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/imba/data_store.rb', line 55 def delete(*keys) data_store.transaction do keys.flatten.each { |key| @data.delete(key) } @data.commit end end |
.init ⇒ Object
9 10 11 12 13 14 |
# File 'lib/imba/data_store.rb', line 9 def init @data = PStore.new(path, true) @data.ultra_safe = true @data.transaction { @data.commit } @data end |
.inspect ⇒ Object
66 67 68 69 |
# File 'lib/imba/data_store.rb', line 66 def inspect data_store "#<#{name}:#{ruby_like_object_id} #{instance_vars}>" end |
.key?(key) ⇒ Boolean
51 52 53 |
# File 'lib/imba/data_store.rb', line 51 def key?(key) data_store.transaction(true) { @data.root?(key) } end |
.to_a ⇒ Object
40 41 42 |
# File 'lib/imba/data_store.rb', line 40 def to_a Imba::DataStore.all.each_with_object([]) { |id, ary| ary << "#{id}: #{Imba::DataStore[id]}" } end |
.to_hash ⇒ Object
36 37 38 |
# File 'lib/imba/data_store.rb', line 36 def to_hash Imba::DataStore.all.each_with_object({}) { |id, hsh| hsh[id] = Imba::DataStore[id] } end |
.transaction ⇒ Object
44 45 46 47 48 49 |
# File 'lib/imba/data_store.rb', line 44 def transaction data_store.transaction do yield @data @data.commit end end |