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



16
17
18
# File 'lib/synapse/event_sourcing/snapshot/policy.rb', line 16

def initialize(threshold)
  @threshold = threshold
end

Instance Method Details

#should_snapshot?(aggregate) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


22
23
24
# File 'lib/synapse/event_sourcing/snapshot/policy.rb', line 22

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