Class: PaperTrailDiff::ActivityStep
- Inherits:
-
Object
- Object
- PaperTrailDiff::ActivityStep
- Defined in:
- lib/paper_trail_diff/activity_boundary.rb,
sig/generated/paper_trail_diff/activity_boundary.rbs
Overview
One adjacent transition in a descendant-aware activity timeline.
Instance Attribute Summary collapse
- #diff ⇒ Diff readonly
- #from_boundary ⇒ ActivityBoundary readonly
-
#from_snapshot ⇒ RecordSnapshot?
readonly
The reconstructed states this step was compared between, present only when a caller asked for them.
- #to_boundary ⇒ ActivityBoundary readonly
- #to_snapshot ⇒ RecordSnapshot? readonly
Class Method Summary collapse
-
.between(from_boundary:, to_boundary:, from_snapshot:, to_snapshot:, retain:) ⇒ ActivityStep
Compares two reconstructed states and keeps them only when asked, which is every caller's shape: the diff always comes from the pair, the pair itself is retained on request.
Instance Method Summary collapse
-
#empty? ⇒ Boolean
: () -> bool.
-
#initialize(from_boundary:, to_boundary:, diff:, from_snapshot: nil, to_snapshot: nil) ⇒ ActivityStep
constructor
: (from_boundary: ActivityBoundary, to_boundary: ActivityBoundary, diff: Diff, ?from_snapshot: RecordSnapshot?, ?to_snapshot: RecordSnapshot?) -> void.
-
#to_h ⇒ Hash[Symbol, untyped]
: () -> Hash[Symbol, untyped].
Constructor Details
#initialize(from_boundary:, to_boundary:, diff:, from_snapshot: nil, to_snapshot: nil) ⇒ ActivityStep
: (from_boundary: ActivityBoundary, to_boundary: ActivityBoundary, diff: Diff, ?from_snapshot: RecordSnapshot?, ?to_snapshot: RecordSnapshot?) -> void
134 135 136 137 138 139 140 141 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 134 def initialize(from_boundary:, to_boundary:, diff:, from_snapshot: nil, to_snapshot: nil) @from_boundary = from_boundary @to_boundary = to_boundary @diff = diff @from_snapshot = from_snapshot @to_snapshot = to_snapshot freeze end |
Instance Attribute Details
#diff ⇒ Diff (readonly)
110 111 112 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 110 def diff @diff end |
#from_boundary ⇒ ActivityBoundary (readonly)
108 109 110 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 108 def from_boundary @from_boundary end |
#from_snapshot ⇒ RecordSnapshot? (readonly)
The reconstructed states this step was compared between, present only when a caller asked for them. A diff carries what changed; a renderer that has to name an unchanged field of a changed record needs the whole state, and rebuilding it from the version table by hand is both slower and easy to get wrong.
116 117 118 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 116 def from_snapshot @from_snapshot end |
#to_boundary ⇒ ActivityBoundary (readonly)
109 110 111 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 109 def to_boundary @to_boundary end |
#to_snapshot ⇒ RecordSnapshot? (readonly)
117 118 119 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 117 def to_snapshot @to_snapshot end |
Class Method Details
.between(from_boundary:, to_boundary:, from_snapshot:, to_snapshot:, retain:) ⇒ ActivityStep
Compares two reconstructed states and keeps them only when asked, which is every caller's shape: the diff always comes from the pair, the pair itself is retained on request. : (from_boundary: ActivityBoundary, to_boundary: ActivityBoundary, from_snapshot: RecordSnapshot?, to_snapshot: RecordSnapshot?, retain: bool) -> ActivityStep
123 124 125 126 127 128 129 130 131 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 123 def self.between(from_boundary:, to_boundary:, from_snapshot:, to_snapshot:, retain:) new( from_boundary: from_boundary, to_boundary: to_boundary, diff: Engine.compare(from_snapshot, to_snapshot), from_snapshot: (from_snapshot if retain), to_snapshot: (to_snapshot if retain) ) end |
Instance Method Details
#empty? ⇒ Boolean
: () -> bool
144 145 146 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 144 def empty? diff.empty? end |
#to_h ⇒ Hash[Symbol, untyped]
: () -> Hash[Symbol, untyped]
149 150 151 152 153 154 155 |
# File 'lib/paper_trail_diff/activity_boundary.rb', line 149 def to_h { from: from_boundary.to_h, to: to_boundary.to_h, diff: diff.to_h } end |