Class: AggregateRoot::Repository
- Inherits:
-
Object
- Object
- AggregateRoot::Repository
- Defined in:
- lib/aggregate_root/repository.rb
Instance Attribute Summary collapse
-
#event_store ⇒ Object
Returns the value of attribute event_store.
Instance Method Summary collapse
- #default_event_store ⇒ Object
-
#initialize(event_store = default_event_store) ⇒ Repository
constructor
A new instance of Repository.
- #load(aggregate) ⇒ Object
- #store(aggregate) ⇒ Object
Constructor Details
#initialize(event_store = default_event_store) ⇒ Repository
Returns a new instance of Repository.
3 4 5 |
# File 'lib/aggregate_root/repository.rb', line 3 def initialize(event_store = default_event_store) @event_store = event_store end |
Instance Attribute Details
#event_store ⇒ Object
Returns the value of attribute event_store.
20 21 22 |
# File 'lib/aggregate_root/repository.rb', line 20 def event_store @event_store end |
Instance Method Details
#default_event_store ⇒ Object
22 23 24 |
# File 'lib/aggregate_root/repository.rb', line 22 def default_event_store AggregateRoot.configuration.default_event_store end |
#load(aggregate) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/aggregate_root/repository.rb', line 13 def load(aggregate) events = event_store.read_stream_events_forward(aggregate.id) events.each do |event| aggregate.apply_old_event(event) end end |
#store(aggregate) ⇒ Object
7 8 9 10 11 |
# File 'lib/aggregate_root/repository.rb', line 7 def store(aggregate) aggregate.unpublished_events.each do |event| event_store.publish_event(event, aggregate.id) end end |