Class: Synapse::EventSourcing::TriggeringEventStream

Inherits:
CountingEventStream show all
Defined in:
lib/synapse/event_sourcing/snapshot/count_stream.rb

Overview

Event stream decorator that counts each event retrieved from the delegate stream and registers a listener with the current unit of work that can trigger a snapshot after the unit of work has been cleaned up

Instance Method Summary collapse

Methods inherited from CountingEventStream

#next_event

Methods inherited from Domain::DomainEventStream

#each, #next_event, #peek, #to_a

Constructor Details

#initialize(delegate, counter, type_identifier, aggregate_id, trigger) ⇒ undefined

Parameters:

  • delegate (DomainEventStream)
  • counter (Atomic)
  • type_identifier (String)
  • aggregate_id (Object)
  • trigger (EventCountSnapshotTrigger)


40
41
42
43
44
45
46
# File 'lib/synapse/event_sourcing/snapshot/count_stream.rb', line 40

def initialize(delegate, counter, type_identifier, aggregate_id, trigger)
  super delegate, counter

  @type_identifier = type_identifier
  @aggregate_id = aggregate_id
  @trigger = trigger
end

Instance Method Details

#end?Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/synapse/event_sourcing/snapshot/count_stream.rb', line 49

def end?
  the_end = @delegate.end?

  if the_end
    listener = SnapshotUnitOfWorkListener.new @type_identifier, @aggregate_id, @counter, @trigger

    unit = @trigger.unit_provider.current
    unit.register_listener listener

    @trigger.clear_counter @aggregate_id
  end

  the_end
end