class EventSourcing::Event::Store::Memory

Public Class Methods

new() click to toggle source
# File lib/event_sourcing/event/store/memory.rb, line 9
def initialize
  @events_with_stream_id = []
end

Public Instance Methods

<<(stream_id, expected_version, events)
Alias for: append
append(stream_id, expected_version, events) click to toggle source
# 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
Also aliased as: <<, push
events() click to toggle source
# File lib/event_sourcing/event/store/memory.rb, line 13
def events
  @events_with_stream_id.map { |e| e[:event] }
end
get_stream(id) click to toggle source
# 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
push(stream_id, expected_version, events)
Alias for: append

Protected Instance Methods

events_for(stream_id) click to toggle source
# File lib/event_sourcing/event/store/memory.rb, line 37
def events_for(stream_id)
  @events_with_stream_id.select { |event| event[:stream_id] == stream_id }.map { |event| event[:event] }
end