class Synapse::EventSourcing::SnapshotUnitOfWorkListener

Unit of work listener that schedules snapshots

Public Class Methods

new(type_identifier, aggregate, policy, taker) click to toggle source

@param [String] type_identifier @param [AggregateRoot] aggregate @param [SnapshotPolicy] policy @param [SnapshotTaker] taker @return [undefined]

# File lib/synapse/event_sourcing/snapshot/unit_listener.rb, line 10
def initialize(type_identifier, aggregate, policy, taker)
  @type_identifier = type_identifier
  @aggregate = aggregate
  @policy = policy
  @taker = taker
end

Public Instance Methods

on_cleanup(unit) click to toggle source

@param [UnitOfWork] unit @return [undefined]

# File lib/synapse/event_sourcing/snapshot/unit_listener.rb, line 19
def on_cleanup(unit)
  if @policy.should_snapshot? @aggregate
    @taker.schedule_snapshot @type_identifier, @aggregate.id
  end
end