Module: Replay::Repository::ClassMethods
- Defined in:
- lib/replay/repository.rb
Class Method Summary collapse
-
.refresh(obj) ⇒ Object
refresh reloads the object from the data store naive implementation is just a reload.
Instance Method Summary collapse
- #configuration ⇒ Object
- #configure {|@configuration| ... } ⇒ Object
-
#load(klass, stream_id, options = {}) ⇒ Object
load will always return an initialized instance of the supplied class (unless it doesn’t!).
- #prepare(obj) ⇒ Object
- #repository_load(klass, stream_id, options = {}) ⇒ Object
- #store ⇒ Object
Class Method Details
.refresh(obj) ⇒ Object
refresh reloads the object from the data store naive implementation is just a reload. Once deltas are in place it can just apply the delta events to the object
38 39 40 41 |
# File 'lib/replay/repository.rb', line 38 def self.refresh(obj) new_obj = load(obj.class, obj.to_key) new_obj end |
Instance Method Details
#configuration ⇒ Object
8 9 10 |
# File 'lib/replay/repository.rb', line 8 def configuration @configuration ||= Configuration.new end |
#configure {|@configuration| ... } ⇒ Object
50 51 52 53 54 |
# File 'lib/replay/repository.rb', line 50 def configure @configuration ||= Configuration.new yield @configuration @configuration end |
#load(klass, stream_id, options = {}) ⇒ Object
load will always return an initialized instance of the supplied class (unless it doesn’t!). if the given stream has no events (e.g. is not found, new object, etc), load will attempt to call create on the newly initalized instance of klass
options:
:create => true #if false, do not call create on this instance if no stream is found
18 19 20 |
# File 'lib/replay/repository.rb', line 18 def load(klass, stream_id, ={}) repository_load(klass, stream_id, ) end |
#prepare(obj) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/replay/repository.rb', line 43 def prepare(obj) @configuration.subscribers.each do |subscriber| obj.add_subscriber(subscriber) end obj end |
#repository_load(klass, stream_id, options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/replay/repository.rb', line 22 def repository_load(klass, stream_id, ={}) events = store.event_stream(stream_id) if events.empty? raise Errors::EventStreamNotFoundError.new("Could not find any events for stream identifier #{stream_id}") if [:create].nil? end obj = prepare(klass.new) obj.create(stream_id) if [:create] && events.empty? obj.apply(events) obj end |
#store ⇒ Object
56 57 58 |
# File 'lib/replay/repository.rb', line 56 def store @configuration.store end |