class Synapse::EventSourcing::ConflictResolvingUnitOfWorkListener
Unit of work listener that detects if there is a conflict before an aggregate is committed If there is a potential conflict, a conflict resolver determines how to resolve the conflict.
Public Class Methods
new(aggregate, unseen_events, conflict_resolver)
click to toggle source
@param [AggregateRoot] aggregate @param [Array] unseen_events @param [ConflictResolver] conflict_resolver @return [undefined]
# File lib/synapse/event_sourcing/conflict_resolver.rb, line 38 def initialize(aggregate, unseen_events, conflict_resolver) @aggregate = aggregate @unseen_events = unseen_events @conflict_resolver = conflict_resolver end
Public Instance Methods
on_prepare_commit(unit, aggregates, events)
click to toggle source
@param [UnitOfWork] unit @param [Array<AggregateRoot>] aggregates @param [Hash<EventBus, Array>] events @return [undefined]
# File lib/synapse/event_sourcing/conflict_resolver.rb, line 48 def on_prepare_commit(unit, aggregates, events) if potential_conflicts? @conflict_resolver.resolve_conflicts @aggregate.uncommitted_events.to_a, @unseen_events end end
Private Instance Methods
potential_conflicts?()
click to toggle source
@return [Boolean]
# File lib/synapse/event_sourcing/conflict_resolver.rb, line 57 def potential_conflicts? @aggregate.uncommitted_event_count > 0 and @aggregate.version and @unseen_events.size > 0 end