Class: Synapse::EventSourcing::IntervalSnapshotPolicy

Inherits:
SnapshotPolicy
  • Object
show all
Defined in:
lib/synapse/event_sourcing/snapshot/policy.rb

Overview

Snapshot policy that takes a snapshot if the number of events committed in an aggregate since the last snapshot goes over the configured threshold

Instance Method Summary collapse

Constructor Details

#initialize(threshold) ⇒ undefined

Parameters:

  • threshold (Integer)


19
20
21
# File 'lib/synapse/event_sourcing/snapshot/policy.rb', line 19

def initialize(threshold)
  @threshold = threshold
end

Instance Method Details

#should_snapshot?(aggregate) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


25
26
27
# File 'lib/synapse/event_sourcing/snapshot/policy.rb', line 25

def should_snapshot?(aggregate)
  (aggregate.version - (aggregate.initial_version or 0)) >= @threshold
end