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, metadata = {}) ⇒ Object
- #repository_load(klass_or_instance, 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
51 52 53 54 55 |
# File 'lib/replay/repository.rb', line 51 def configure @configuration ||= Configuration.default 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, metadata = {}) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/replay/repository.rb', line 43 def prepare(obj, ={}) obj.subscription_manager = SubscriptionManager.new(configuration.logger, ) @configuration.subscribers.each do |subscriber| obj.add_subscriber(subscriber) end obj end |
#repository_load(klass_or_instance, 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_or_instance, stream_id, ={}) stream = store.event_stream(stream_id) if stream.empty? && configuration.reject_load_on_empty_stream? raise Errors::EventStreamNotFoundError.new("Could not find any events for stream identifier #{stream_id}") if [:create].nil? end obj = klass_or_instance.is_a?(Class) ? prepare(klass.new, [:metadata]) : klass_or_instance obj.create(stream_id) if [:create] && stream.empty? obj.apply(stream.map(&:event)) obj end |
#store ⇒ Object
57 58 59 |
# File 'lib/replay/repository.rb', line 57 def store @configuration.store end |