Class: RST::Persistent::Store Abstract
- Inherits:
-
Object
- Object
- RST::Persistent::Store
- Defined in:
- lib/modules/persistent/store.rb
Overview
public API-methods should not be overwritten by descendant classes. But descendants must overwrite all methods marked as abstract here.
# The abstract Store-base-class
Store provides the interface for all store-able classes
Direct Known Subclasses
PUBLIC API collapse
-
#-(object) ⇒ Store
Remove an object from the store.
-
#<<(object) ⇒ Object
Add an object and sync store.
-
#create ⇒ Persistentable
Create objects and set the object’s store-attribute.
- #find(*ids) ⇒ nil, ...
-
#first ⇒ Object|nil
The first object in the store or nil if the store is empty.
-
#initialize(args = {}) ⇒ Store
constructor
Sets options-hash and calls the abstract ‘setup_backend’-callback.
ABSTRACT METHODS TO BE OVERWRITTEN IN DESCENDANTS collapse
-
#all ⇒ Object
abstract
Enumerable.
-
#delete! ⇒ Object
abstract
Delete the store.
-
#update(object) ⇒ Object
abstract
Find and update or add an object to the store.
Constructor Details
#initialize(args = {}) ⇒ Store
Sets options-hash and calls the abstract ‘setup_backend’-callback
21 22 23 24 |
# File 'lib/modules/persistent/store.rb', line 21 def initialize(args={}) @options = {}.merge(args) setup_backend end |
Instance Method Details
#-(object) ⇒ Store
Remove an object from the store
35 36 37 38 |
# File 'lib/modules/persistent/store.rb', line 35 def -(object) remove_object(object) self end |
#<<(object) ⇒ Object
Add an object and sync store
28 29 30 |
# File 'lib/modules/persistent/store.rb', line 28 def <<(object) update(object) end |
#all ⇒ Object
Overwrite in descendants thus it returns an Enumerable of all objects in the store
Returns Enumerable.
73 74 75 |
# File 'lib/modules/persistent/store.rb', line 73 def all raise AbstractMethodCallError.new end |
#create ⇒ Persistentable
Create objects and set the object’s store-attribute
62 63 64 65 66 67 |
# File 'lib/modules/persistent/store.rb', line 62 def create obj = yield obj.store = self self << obj obj end |
#delete! ⇒ Object
-
override this method in descendants thus the store removes all objects.
Delete the store
79 80 81 |
# File 'lib/modules/persistent/store.rb', line 79 def delete! raise AbstractMethodCallError.new end |
#find(*ids) ⇒ nil, ...
49 50 51 |
# File 'lib/modules/persistent/store.rb', line 49 def find(*ids) flatten all.select { |obj| ids.include?(obj.id) } end |
#first ⇒ Object|nil
Returns the first object in the store or nil if the store is empty.
41 42 43 |
# File 'lib/modules/persistent/store.rb', line 41 def first all.first end |
#update(object) ⇒ Object
-
override in other StoreClasses
Find and update or add an object to the store
86 87 88 |
# File 'lib/modules/persistent/store.rb', line 86 def update(object) raise AbstractMethodCallError.new end |