Class: Synapse::Domain::SimpleDomainEventStream

Inherits:
DomainEventStream show all
Defined in:
lib/synapse/domain/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.



74
75
76
77
# File 'lib/synapse/domain/stream.rb', line 74

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)


81
82
83
# File 'lib/synapse/domain/stream.rb', line 81

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:



89
90
91
92
93
94
95
96
# File 'lib/synapse/domain/stream.rb', line 89

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:



102
103
104
105
# File 'lib/synapse/domain/stream.rb', line 102

def peek
  assert_valid
  @events.at @next_index
end