module RubyCqrs::Domain::Snapshotable
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/ruby_cqrs/domain/snapshotable.rb, line 4 def initialize if self.class.const_defined? :SNAPSHOT_THRESHOLD @snapshot_threshold = self.class.const_get(:SNAPSHOT_THRESHOLD) else @snapshot_threshold = 30 end @snapshot_threshold = 30 if @snapshot_threshold <= 0 @countdown = @snapshot_threshold @reset_snapshot_countdown_flag = false super end
Private Instance Methods
apply_snapshot(snapshot_object)
click to toggle source
# File lib/ruby_cqrs/domain/snapshotable.rb, line 43 def apply_snapshot snapshot_object raise NotImplementedError end
reset_countdown(loaded_event_count)
click to toggle source
# File lib/ruby_cqrs/domain/snapshotable.rb, line 25 def reset_countdown loaded_event_count @countdown = @snapshot_threshold - loaded_event_count @reset_snapshot_countdown_flag = false end
set_snapshot_taken()
click to toggle source
# File lib/ruby_cqrs/domain/snapshotable.rb, line 34 def set_snapshot_taken @reset_snapshot_countdown_flag = true end
should_reset_snapshot_countdown?()
click to toggle source
# File lib/ruby_cqrs/domain/snapshotable.rb, line 30 def should_reset_snapshot_countdown? @reset_snapshot_countdown_flag end
should_take_a_snapshot?()
click to toggle source
# File lib/ruby_cqrs/domain/snapshotable.rb, line 17 def should_take_a_snapshot? @countdown <= 0 end
snapshot_countdown()
click to toggle source
# File lib/ruby_cqrs/domain/snapshotable.rb, line 21 def snapshot_countdown @countdown -= 1 end
take_a_snapshot()
click to toggle source
the including domain object should implement these two methods
# File lib/ruby_cqrs/domain/snapshotable.rb, line 39 def take_a_snapshot raise NotImplementedError end