class Synapse::Domain::DomainEventStream

Represents a historical stream of domain events in chronological order

@example

stream = SimpleDomainEventStream.new events
until stream.end?
  puts stream.next_event
end

@example

stream = SimpleDomainEventStream.new events
stream.each do |event|
  puts event
end

@abstract

Public Instance Methods

each() { |next_event| ... } click to toggle source

Yields the next domain events in the stream until the end of the stream has been reached

@yield [DomainEventMessage] The next event in the event stream @return [undefined]

# File lib/synapse/domain/stream.rb, line 47
def each
  until end?
    yield next_event
  end
end
end?() click to toggle source

Returns true if the end of the stream has been reached

@abstract @return [Boolean]

# File lib/synapse/domain/stream.rb, line 23
def end?
  raise NotImplementedError
end
next_event() click to toggle source

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

@abstract @return [DomainEventMessage]

# File lib/synapse/domain/stream.rb, line 31
def next_event
  raise NotImplementedError
end
peek() click to toggle source

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

@abstract @return [DomainEventMessage]

# File lib/synapse/domain/stream.rb, line 39
def peek
  raise NotImplementedError
end
to_a() click to toggle source

Returns the domain events in this stream as an array @return [Array<DomainEventMessage>]

# File lib/synapse/domain/stream.rb, line 55
def to_a
  events = Array.new
  each do |event|
    events.push event
  end

  events
end

Protected Instance Methods

assert_valid() click to toggle source

@raise [EndOfStreamError] If at the end of the stream @return [undefined]

# File lib/synapse/domain/stream.rb, line 68
def assert_valid
  raise EndOfStreamError if end?
end