Class: Synapse::EventSourcing::CapturingEventStream

Inherits:
Domain::DomainEventStream show all
Extended by:
Forwardable
Defined in:
lib/synapse/event_sourcing/conflict_resolver.rb

Overview

Event stream decorator that captures any events that have been applied after the expected version of an aggregate

Instance Method Summary collapse

Methods inherited from Domain::DomainEventStream

#each, #end?, #peek, #to_a

Constructor Details

#initialize(delegate, unseen_events, expected_version) ⇒ undefined

Parameters:

  • delegate (DomainEventStream)
  • unseen_events (Array)
  • expected_version (Integer)


73
74
75
76
77
# File 'lib/synapse/event_sourcing/conflict_resolver.rb', line 73

def initialize(delegate, unseen_events, expected_version)
  @delegate = delegate
  @unseen_events = unseen_events
  @expected_version = expected_version
end

Instance Method Details

#next_eventDomainEventMessage

Returns:

  • (DomainEventMessage)


80
81
82
83
84
85
86
# File 'lib/synapse/event_sourcing/conflict_resolver.rb', line 80

def next_event
  @delegate.next_event.tap do |event|
    if @expected_version and event.sequence_number > @expected_version
      @unseen_events.push event
    end
  end
end