Class: EventSourcing::Event::Store::Memory
- Inherits:
-
Object
- Object
- EventSourcing::Event::Store::Memory
- Defined in:
- lib/event_sourcing/event/store/memory.rb
Instance Method Summary collapse
- #append(stream_id, expected_version, events) ⇒ Object (also: #<<, #push)
- #events ⇒ Object
- #get_stream(id) ⇒ Object
-
#initialize ⇒ Memory
constructor
A new instance of Memory.
Constructor Details
#initialize ⇒ Memory
Returns a new instance of Memory.
9 10 11 |
# File 'lib/event_sourcing/event/store/memory.rb', line 9 def initialize @events_with_stream_id = [] end |
Instance Method Details
#append(stream_id, expected_version, events) ⇒ Object Also known as: <<, push
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/event_sourcing/event/store/memory.rb', line 22 def append(stream_id, expected_version, events) raise EventSourcing::Event::Store::ConcurrencyError if get_stream(stream_id).version != expected_version Array(events).tap do |events| events.each do |event| @events_with_stream_id.push(stream_id: stream_id, event: event) end end nil end |
#events ⇒ Object
13 14 15 |
# File 'lib/event_sourcing/event/store/memory.rb', line 13 def events @events_with_stream_id.map { |e| e[:event] } end |
#get_stream(id) ⇒ Object
17 18 19 20 |
# File 'lib/event_sourcing/event/store/memory.rb', line 17 def get_stream(id) events = events_for(id) EventSourcing::Event::Stream.new(id, events, events.count, self) end |