Class: Synapse::Domain::SimpleDomainEventStream

Inherits:
DomainEventStream show all
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

Methods inherited from DomainEventStream

#each, #to_a

Constructor Details

#initialize(*events) ⇒ SimpleDomainEventStream

Returns a new instance of SimpleDomainEventStream.



5
6
7
8
# File 'lib/synapse/domain/simple_stream.rb', line 5

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

Returns:

  • (Boolean)


12
13
14
# File 'lib/synapse/domain/simple_stream.rb', line 12

def end?
  @next_index >= @events.size
end

#next_eventDomainEventMessage

Returns the next event in the stream and moves the stream’s pointer forward

Returns:

Raises:



20
21
22
23
24
25
26
27
# File 'lib/synapse/domain/simple_stream.rb', line 20

def next_event
  assert_valid

  event = @events.at @next_index
  @next_index += 1

  event
end

#peekDomainEventMessage

Returns the next event in the stream without moving the stream’s pointer forward

Returns:

Raises:



33
34
35
36
# File 'lib/synapse/domain/simple_stream.rb', line 33

def peek
  assert_valid
  @events.at @next_index
end