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) {|Object| ... } ⇒ 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={}) = {}.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.
80 81 82 |
# File 'lib/modules/persistent/store.rb', line 80 def all raise AbstractMethodCallError.new end |
#create ⇒ Persistentable
Create objects and set the object’s store-attribute
69 70 71 72 73 74 |
# File 'lib/modules/persistent/store.rb', line 69 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
86 87 88 |
# File 'lib/modules/persistent/store.rb', line 86 def delete! raise AbstractMethodCallError.new end |
#find(*ids) {|Object| ... } ⇒ nil, ...
50 51 52 53 54 55 56 57 58 |
# File 'lib/modules/persistent/store.rb', line 50 def find(*ids) if block_given? all.select { |obj| ids.include?(obj.id) }.each do |obj| yield(obj) end else flatten all.select { |obj| ids.include?(obj.id) } end 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
93 94 95 |
# File 'lib/modules/persistent/store.rb', line 93 def update(object) raise AbstractMethodCallError.new end |