Class: Geode::Store
- Inherits:
-
Object
- Object
- Geode::Store
- Defined in:
- lib/geode.rb
Overview
Subclass this to implement your own stores.
Direct Known Subclasses
Instance Method Summary collapse
-
#[](key) ⇒ Object
Retrieve the object at ‘key` from the store.
-
#destroy ⇒ Object
“Destroy” the store, deleting all data.
-
#initialize(name, connection = nil) ⇒ Store
constructor
Connect to a store.
-
#open {|table| ... } ⇒ Object
“Open” the store for reading and/or writing.
-
#peek ⇒ Hash
“Peek” inside the store, returning a copy of its table.
Constructor Details
#initialize(name, connection = nil) ⇒ Store
Connect to a store.
7 8 9 |
# File 'lib/geode.rb', line 7 def initialize(name, connection = nil) @name = name.to_s end |
Instance Method Details
#[](key) ⇒ Object
Retrieve the object at ‘key` from the store. This is implemented using `#peek` and therefore changes to the object returned by this method will NOT be persisted in the store. Use this if you simply need to fetch a value from the store.
44 45 46 |
# File 'lib/geode.rb', line 44 def [](key) peek[key] end |
#destroy ⇒ Object
“Destroy” the store, deleting all data. The store can be opened again, recreating it in a blank state.
50 51 52 |
# File 'lib/geode.rb', line 50 def destroy raise 'subclasses must implement #destroy' end |
#open {|table| ... } ⇒ Object
“Open” the store for reading and/or writing. be persisted in the store When in doubt, use this method.
21 22 23 |
# File 'lib/geode.rb', line 21 def open raise 'subclasses must implement #open' end |
#peek ⇒ Hash
“Peek” inside the store, returning a copy of its table. Changes to this copy will NOT be persisted in the store. Use this if you simply want to view the store’s table.
31 32 33 |
# File 'lib/geode.rb', line 31 def peek open(&:itself) end |