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) ⇒ undefined

Parameters:



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

Returns:

  • (Boolean)


14
15
16
# File 'lib/synapse/domain/simple_stream.rb', line 14

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:



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

#peekDomainEventMessage

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

Returns:

Raises:



35
36
37
38
# File 'lib/synapse/domain/simple_stream.rb', line 35

def peek
  assert_valid
  @events.at @next_index
end