Class: Lieutenant::EventStore
- Inherits:
-
Object
- Object
- Lieutenant::EventStore
- Defined in:
- lib/lieutenant/event_store.rb,
lib/lieutenant/event_store/in_memory.rb
Overview
Event stores handles pushing and pulling events from the event store.
Defined Under Namespace
Classes: InMemory
Instance Method Summary collapse
- #event_stream_for(aggregate_id) ⇒ Object
-
#initialize(store, event_bus) ⇒ EventStore
constructor
A new instance of EventStore.
- #save_events(aggregate_id, events, expected_version) ⇒ Object
- #transaction(&blk) ⇒ Object
Constructor Details
#initialize(store, event_bus) ⇒ EventStore
Returns a new instance of EventStore.
8 9 10 11 |
# File 'lib/lieutenant/event_store.rb', line 8 def initialize(store, event_bus) @store = store @event_bus = event_bus end |
Instance Method Details
#event_stream_for(aggregate_id) ⇒ Object
22 23 24 |
# File 'lib/lieutenant/event_store.rb', line 22 def event_stream_for(aggregate_id) store.event_stream_for(aggregate_id) || raise(Exception::AggregateNotFound, aggregate_id) end |
#save_events(aggregate_id, events, expected_version) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/lieutenant/event_store.rb', line 13 def save_events(aggregate_id, events, expected_version) raise(Exception::ConcurrencyConflict) if store.aggregate_sequence_number(aggregate_id) != expected_version PREPARE_EVENTS[aggregate_id, events, expected_version].tap do |final_events| store.persist(final_events) final_events.each(&event_bus.method(:publish)) end end |
#transaction(&blk) ⇒ Object
26 27 28 |
# File 'lib/lieutenant/event_store.rb', line 26 def transaction(&blk) store.transaction(&blk) end |