Class: Lieutenant::EventStore::InMemory
- Inherits:
-
Object
- Object
- Lieutenant::EventStore::InMemory
- Defined in:
- lib/lieutenant/event_store/in_memory.rb
Overview
Memory implementation of the event store. Stores events while the application is running
Instance Method Summary collapse
- #aggregate_sequence_number(aggregate_id) ⇒ Object
- #event_stream_for(aggregate_id) ⇒ Object
-
#initialize ⇒ InMemory
constructor
A new instance of InMemory.
- #persist(events) ⇒ Object
- #transaction ⇒ Object
Constructor Details
#initialize ⇒ InMemory
Returns a new instance of InMemory.
7 8 9 |
# File 'lib/lieutenant/event_store/in_memory.rb', line 7 def initialize @store = {} end |
Instance Method Details
#aggregate_sequence_number(aggregate_id) ⇒ Object
21 22 23 24 |
# File 'lib/lieutenant/event_store/in_memory.rb', line 21 def aggregate_sequence_number(aggregate_id) return -1 unless store.key?(aggregate_id) store[aggregate_id].last.sequence_number end |
#event_stream_for(aggregate_id) ⇒ Object
15 16 17 18 19 |
# File 'lib/lieutenant/event_store/in_memory.rb', line 15 def event_stream_for(aggregate_id) events = store[aggregate_id] return nil unless events Enumerator.new { |yielder| events.each(&yielder.method(:<<)) } end |
#persist(events) ⇒ Object
11 12 13 |
# File 'lib/lieutenant/event_store/in_memory.rb', line 11 def persist(events) events.each { |event| (store[event.aggregate_id] ||= []).push(event) } end |
#transaction ⇒ Object
26 27 28 29 |
# File 'lib/lieutenant/event_store/in_memory.rb', line 26 def transaction # In memory event store currently does not support transactions. yield end |