Class: Moneta::Adapters::PStore
- Inherits:
-
PStore
- Object
- PStore
- Moneta::Adapters::PStore
- Includes:
- Defaults
- Defined in:
- lib/moneta/adapters/pstore.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
-
#initialize(options = {}) ⇒ PStore
constructor
A new instance of PStore.
- #key?(key) ⇒ Boolean
- #keys ⇒ Object
- #store(key, value) ⇒ Object
Methods included from Defaults
Constructor Details
#initialize(options = {}) ⇒ PStore
Returns a new instance of PStore.
8 9 10 11 |
# File 'lib/moneta/adapters/pstore.rb', line 8 def initialize( = {}) [:path] ||= ::File.join Dir.pwd, 'data.pstore' super [:path] end |
Instance Method Details
#[](key) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/moneta/adapters/pstore.rb', line 25 def [](key) transaction true do struct = super key_for(key) struct ? struct['value'] : nil end end |
#clear ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/moneta/adapters/pstore.rb', line 49 def clear(*) transaction do @table.keys.each do |key| delete key end end end |
#delete(key) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/moneta/adapters/pstore.rb', line 32 def delete(key) struct = if @transaction super key_for(key) else transaction do super key_for(key) end end struct ? struct['value'] : nil end |
#key?(key) ⇒ Boolean
13 14 15 16 17 |
# File 'lib/moneta/adapters/pstore.rb', line 13 def key?(key) transaction do root? key_for(key) end end |
#keys ⇒ Object
19 20 21 22 23 |
# File 'lib/moneta/adapters/pstore.rb', line 19 def keys transaction true do roots end end |
#store(key, value) ⇒ Object
43 44 45 46 47 |
# File 'lib/moneta/adapters/pstore.rb', line 43 def store(key, value, *) transaction do (@table[key_for(key)] ||= {})['value'] = value end end |