Class: PaperTrailDiff::ActivityHistoryBuilder
- Inherits:
-
Object
- Object
- PaperTrailDiff::ActivityHistoryBuilder
- Defined in:
- lib/paper_trail_diff/activity_history.rb,
sig/generated/paper_trail_diff/activity_history.rbs
Overview
Builds activity steps while retaining root snapshots for combined analysis.
Instance Method Summary collapse
-
#append_step(boundary, snapshot) ⇒ void
: (ActivityBoundary, RecordSnapshot?) -> void.
-
#call ⇒ ActivityHistory
: () -> ActivityHistory.
-
#capture_first(snapshot) ⇒ void
: (RecordSnapshot?) -> void.
-
#consume(event, snapshot) ⇒ void
: (ActivityEvent, RecordSnapshot?) -> void.
-
#final_snapshot ⇒ RecordSnapshot?
: () -> RecordSnapshot?.
-
#include_previous_step? ⇒ Boolean
: () -> bool.
- #initialize(root_versions, events, snapshotter, current: nil, include_step: nil, snapshots: false) ⇒ ActivityHistoryBuilder constructor
-
#reset ⇒ void
: () -> void.
-
#sequence ⇒ ActivitySnapshotSequence
: () -> ActivitySnapshotSequence.
-
#version_key(version) ⇒ Array[untyped]
: (untyped) -> Array.
Constructor Details
#initialize(root_versions, events, snapshotter, current: nil, include_step: nil, snapshots: false) ⇒ ActivityHistoryBuilder
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/paper_trail_diff/activity_history.rb', line 30 def initialize( # rubocop:disable Metrics/ParameterLists root_versions, events, snapshotter, current: nil, include_step: nil, snapshots: false ) @root_versions = root_versions @events = events @snapshotter = snapshotter @current = current @include_step = include_step @snapshots = snapshots end |
Instance Method Details
#append_step(boundary, snapshot) ⇒ void
This method returns an undefined value.
: (ActivityBoundary, RecordSnapshot?) -> void
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/paper_trail_diff/activity_history.rb', line 111 def append_step(boundary, snapshot) return unless include_previous_step? previous_boundary = @previous_boundary return unless previous_boundary @steps << ActivityStep.between( from_boundary: previous_boundary, to_boundary: boundary, from_snapshot: @previous_snapshot, to_snapshot: snapshot, retain: @snapshots ) @selected_last_snapshot = snapshot end |
#call ⇒ ActivityHistory
: () -> ActivityHistory
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/paper_trail_diff/activity_history.rb', line 42 def call reset sequence.each { |event, snapshot| consume(event, snapshot) } ActivityHistory.new( steps: @steps, root_snapshots: @root_snapshots, first_snapshot: @first_snapshot, last_snapshot: final_snapshot ) end |
#capture_first(snapshot) ⇒ void
This method returns an undefined value.
: (RecordSnapshot?) -> void
103 104 105 106 107 108 |
# File 'lib/paper_trail_diff/activity_history.rb', line 103 def capture_first(snapshot) return if @first_snapshot_seen @first_snapshot = snapshot @first_snapshot_seen = true end |
#consume(event, snapshot) ⇒ void
This method returns an undefined value.
: (ActivityEvent, RecordSnapshot?) -> void
92 93 94 95 96 97 98 99 100 |
# File 'lib/paper_trail_diff/activity_history.rb', line 92 def consume(event, snapshot) capture_first(snapshot) boundary = ActivityBoundary.from_version(event.version) @root_snapshots[version_key(event.version)] = snapshot if event.root? append_step(boundary, snapshot) if @previous_boundary @previous_boundary = boundary @previous_event = event @previous_snapshot = snapshot end |
#final_snapshot ⇒ RecordSnapshot?
: () -> RecordSnapshot?
130 131 132 |
# File 'lib/paper_trail_diff/activity_history.rb', line 130 def final_snapshot @include_step ? @selected_last_snapshot : @previous_snapshot end |
#include_previous_step? ⇒ Boolean
: () -> bool
125 126 127 |
# File 'lib/paper_trail_diff/activity_history.rb', line 125 def include_previous_step? !@include_step || @include_step.call(@previous_event) end |
#reset ⇒ void
This method returns an undefined value.
: () -> void
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/paper_trail_diff/activity_history.rb', line 70 def reset @steps = [] @root_snapshots = {} @first_snapshot = nil @first_snapshot_seen = false @previous_snapshot = nil @selected_last_snapshot = nil @previous_boundary = nil @previous_event = nil end |
#sequence ⇒ ActivitySnapshotSequence
: () -> ActivitySnapshotSequence
82 83 84 85 86 87 88 89 |
# File 'lib/paper_trail_diff/activity_history.rb', line 82 def sequence ActivitySnapshotSequence.new( @root_versions, @events, @snapshotter, current: @current ) end |
#version_key(version) ⇒ Array[untyped]
: (untyped) -> Array
135 136 137 |
# File 'lib/paper_trail_diff/activity_history.rb', line 135 def version_key(version) [version.class.name, version.id] end |