class Synapse::EventStore::Mongo::CursorDomainEventStream

TODO Document me

Public Class Methods

new(storage_strategy, cursor, last_snapshot_commit, aggregate_id) click to toggle source

@param [StorageStrategy] storage_strategy @param [Mongo::Cursor] cursor @param [Array] last_snapshot_commit @param [Object] aggregate_id @return [undefined]

# File lib/synapse/event_store/mongo/cursor_event_stream.rb, line 11
def initialize(storage_strategy, cursor, last_snapshot_commit, aggregate_id)
  @storage_strategy = storage_strategy
  @cursor = cursor
  @aggregate_id = aggregate_id

  if last_snapshot_commit
    # Current batch is an enumerator
    @current_batch = last_snapshot_commit.each
  else
    @current_batch = [].each
  end

  initialize_next_event
end

Public Instance Methods

end?() click to toggle source

@return [Boolean]

# File lib/synapse/event_store/mongo/cursor_event_stream.rb, line 27
def end?
  @next.nil?
end
next_event() click to toggle source

@return [DomainEventMessage]

# File lib/synapse/event_store/mongo/cursor_event_stream.rb, line 32
def next_event
  @next.tap do
    initialize_next_event
  end
end
peek() click to toggle source

@return [DomainEventMessage]

# File lib/synapse/event_store/mongo/cursor_event_stream.rb, line 39
def peek
  @next
end

Private Instance Methods

initialize_next_event() click to toggle source

@return [undefined]

# File lib/synapse/event_store/mongo/cursor_event_stream.rb, line 46
def initialize_next_event
  begin
    @next = @current_batch.next
  rescue StopIteration
    if @cursor.has_next?
      document = @cursor.next
      @current_batch = @storage_strategy.extract_events(document, @aggregate_id).each

      retry
    else
      @next = nil
    end
  end
end