Class: Synapse::Domain::SimpleDomainEventStream
- Inherits:
-
DomainEventStream
- Object
- DomainEventStream
- Synapse::Domain::SimpleDomainEventStream
- Defined in:
- lib/synapse/domain/simple_stream.rb
Overview
Implementation of a domain event stream that holds a stream of events in memory
Instance Method Summary collapse
-
#end? ⇒ Boolean
Returns true if the end of the stream has been reached.
- #initialize(*events) ⇒ undefined constructor
-
#next_event ⇒ DomainEventMessage
Returns the next event in the stream and moves the stream’s pointer forward.
-
#peek ⇒ DomainEventMessage
Returns the next event in the stream without moving the stream’s pointer forward.
Methods inherited from DomainEventStream
Constructor Details
#initialize(*events) ⇒ undefined
7 8 9 10 |
# File 'lib/synapse/domain/simple_stream.rb', line 7 def initialize(*events) @events = events.flatten @next_index = 0 end |
Instance Method Details
#end? ⇒ Boolean
Returns true if the end of the stream has been reached
14 15 16 |
# File 'lib/synapse/domain/simple_stream.rb', line 14 def end? @next_index >= @events.size end |
#next_event ⇒ DomainEventMessage
Returns the next event in the stream and moves the stream’s pointer forward
22 23 24 25 26 27 28 29 |
# File 'lib/synapse/domain/simple_stream.rb', line 22 def next_event assert_valid event = @events.at @next_index @next_index += 1 event end |
#peek ⇒ DomainEventMessage
Returns the next event in the stream without moving the stream’s pointer forward
35 36 37 38 |
# File 'lib/synapse/domain/simple_stream.rb', line 35 def peek assert_valid @events.at @next_index end |