Class: PaperTrailDiff::ActivitySnapshotSequence
- Inherits:
-
Object
- Object
- PaperTrailDiff::ActivitySnapshotSequence
- Defined in:
- lib/paper_trail_diff/activity_snapshot_sequence.rb,
sig/generated/paper_trail_diff/activity_snapshot_sequence.rbs
Overview
Builds chronological snapshots, refreshing only branches affected by prior events.
Instance Method Summary collapse
-
#advance_root(previous_event, event, previous_snapshot) ⇒ RecordSnapshot?
: (ActivityEvent, ActivityEvent, RecordSnapshot?) -> RecordSnapshot?.
-
#build_root_endpoints ⇒ Hash[untyped, untyped]
: () -> Hash[untyped, untyped].
-
#call ⇒ Array[RecordSnapshot?]
: () -> Array.
-
#each {|arg0, arg1| ... } ⇒ void
: () { (ActivityEvent, RecordSnapshot?) -> void } -> void.
-
#full_snapshot(event) ⇒ RecordSnapshot?
: (ActivityEvent) -> RecordSnapshot?.
-
#incremental_root?(event) ⇒ Boolean
: (ActivityEvent) -> bool.
- #initialize(root_versions, events, snapshotter, current: nil) ⇒ ActivitySnapshotSequence constructor
-
#root_endpoint(activity_version) ⇒ Object
: (untyped) -> untyped.
-
#transition_snapshot(previous_event, event, previous_snapshot) ⇒ RecordSnapshot?
: (ActivityEvent, ActivityEvent, RecordSnapshot?) -> RecordSnapshot?.
Constructor Details
#initialize(root_versions, events, snapshotter, current: nil) ⇒ ActivitySnapshotSequence
66 67 68 69 70 71 72 73 |
# File 'lib/paper_trail_diff/activity_snapshot_sequence.rb', line 66 def initialize(root_versions, events, snapshotter, current: nil) @root_versions = root_versions @events = events @snapshotter = snapshotter @current = current @transaction_groups = ActivityTransactionGroups.new(events) @root_endpoints = build_root_endpoints end |
Instance Method Details
#advance_root(previous_event, event, previous_snapshot) ⇒ RecordSnapshot?
: (ActivityEvent, ActivityEvent, RecordSnapshot?) -> RecordSnapshot?
131 132 133 134 135 136 137 138 |
# File 'lib/paper_trail_diff/activity_snapshot_sequence.rb', line 131 def advance_root(previous_event, event, previous_snapshot) @snapshotter.advance_root( root_endpoint(event.version), event.version, previous_snapshot, event: previous_event ) end |
#build_root_endpoints ⇒ Hash[untyped, untyped]
: () -> Hash[untyped, untyped]
151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/paper_trail_diff/activity_snapshot_sequence.rb', line 151 def build_root_endpoints root_index = 0 endpoints = {} #: Hash[untyped, untyped] endpoints.compare_by_identity @events.each do |event| while @root_versions[root_index] && Support.compare_versions(@root_versions[root_index], event.version).negative? root_index += 1 end endpoint = @root_versions[root_index] || @current || @root_versions.last endpoints[event.version] = endpoint end endpoints end |
#call ⇒ Array[RecordSnapshot?]
: () -> Array
76 77 78 79 80 |
# File 'lib/paper_trail_diff/activity_snapshot_sequence.rb', line 76 def call snapshots = [] #: Array[RecordSnapshot?] each { |_event, snapshot| snapshots << snapshot } snapshots end |
#each {|arg0, arg1| ... } ⇒ void
This method returns an undefined value.
: () { (ActivityEvent, RecordSnapshot?) -> void } -> void
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/paper_trail_diff/activity_snapshot_sequence.rb', line 83 def each first = @events.first return unless first previous_snapshot = full_snapshot(first) yield first, previous_snapshot @events.each_cons(2) do |pair| previous_event = pair.fetch(0) event = pair.fetch(1) previous_snapshot = transition_snapshot(previous_event, event, previous_snapshot) yield event, previous_snapshot end end |
#full_snapshot(event) ⇒ RecordSnapshot?
: (ActivityEvent) -> RecordSnapshot?
141 142 143 |
# File 'lib/paper_trail_diff/activity_snapshot_sequence.rb', line 141 def full_snapshot(event) @snapshotter.call(root_endpoint(event.version), event.version) end |
#incremental_root?(event) ⇒ Boolean
: (ActivityEvent) -> bool
125 126 127 128 |
# File 'lib/paper_trail_diff/activity_snapshot_sequence.rb', line 125 def incremental_root?(event) event.root? && @transaction_groups.isolated?(event) && @snapshotter.respond_to?(:advance_root) end |
#root_endpoint(activity_version) ⇒ Object
: (untyped) -> untyped
146 147 148 |
# File 'lib/paper_trail_diff/activity_snapshot_sequence.rb', line 146 def root_endpoint(activity_version) @root_endpoints.fetch(activity_version) end |
#transition_snapshot(previous_event, event, previous_snapshot) ⇒ RecordSnapshot?
: (ActivityEvent, ActivityEvent, RecordSnapshot?) -> RecordSnapshot?
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/paper_trail_diff/activity_snapshot_sequence.rb', line 107 def transition_snapshot(previous_event, event, previous_snapshot) return advance_root(previous_event, event, previous_snapshot) if incremental_root?(previous_event) branches = @transaction_groups.branches_for(previous_event) return full_snapshot(event) unless branches && @snapshotter.respond_to?(:refresh) @snapshotter.refresh( root_endpoint(event.version), event.version, previous_snapshot, branches, event: previous_event, isolated: @transaction_groups.isolated?(previous_event) ) end |