class Synapse::EventStore::InMemoryEventStore
Implementation of an event store that stores events in memory; for testing purposes and not thread safe
Public Class Methods
new()
click to toggle source
# File lib/synapse/event_store/in_memory.rb, line 6 def initialize @streams = Hash.new end
Public Instance Methods
append_events(type_identifier, stream)
click to toggle source
Appends any events in the given stream to the end of the aggregate's stream
@param [String] type_identifier Type descriptor of the aggregate to append to @param [DomainEventStream] stream @return [undefined]
# File lib/synapse/event_store/in_memory.rb, line 34 def append_events(type_identifier, stream) if stream.end? return end events = events_for stream.peek.aggregate_id until stream.end? events.push stream.next_event end end
clear()
click to toggle source
Clears all streams from this event store
# File lib/synapse/event_store/in_memory.rb, line 11 def clear @streams.clear end
events_for(aggregate_id)
click to toggle source
Creates and/or retrieves an array of events for the given aggregate identifier
@param [Object] aggregate_id @return [Array<DomainEventMessage>]
# File lib/synapse/event_store/in_memory.rb, line 50 def events_for(aggregate_id) if @streams.has_key? aggregate_id return @streams.fetch aggregate_id end @streams.store aggregate_id, Array.new end
read_events(type_identifier, aggregate_id)
click to toggle source
@raise [StreamNotFoundError] If the stream for the given aggregate identifier is empty @param [String] type_identifier Type descriptor of the aggregate to retrieve @param [Object] aggregate_id @return [DomainEventStream]
# File lib/synapse/event_store/in_memory.rb, line 19 def read_events(type_identifier, aggregate_id) events = events_for aggregate_id if events.empty? raise StreamNotFoundError.new type_identifier, aggregate_id end Domain::SimpleDomainEventStream.new events end