Class: PaperTrailDiff::Step
- Inherits:
-
Object
- Object
- PaperTrailDiff::Step
- Defined in:
- lib/paper_trail_diff/step.rb,
sig/generated/paper_trail_diff/step.rbs
Overview
One adjacent transition in a PaperTrail timeline.
Instance Attribute Summary collapse
- #diff ⇒ Diff readonly
- #from_boundary ⇒ ActivityBoundary readonly
- #from_version ⇒ Object readonly
- #to_boundary ⇒ ActivityBoundary readonly
- #to_version ⇒ Object readonly
Instance Method Summary collapse
-
#empty? ⇒ Boolean
: () -> bool.
-
#initialize(from_version:, to_version:, diff:, captured_at: nil) ⇒ Step
constructor
to_versionis nil for the one step that closes on current state, which a window reaching past the last recorded version has to do. -
#to_h ⇒ Hash[Symbol, untyped]
: () -> Hash[Symbol, untyped].
Constructor Details
#initialize(from_version:, to_version:, diff:, captured_at: nil) ⇒ Step
to_version is nil for the one step that closes on current state, which a
window reaching past the last recorded version has to do. Read
to_boundary instead when a caller may have opted into that.
: (from_version: untyped, to_version: untyped, diff: Diff, ?captured_at: untyped) -> void
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/paper_trail_diff/step.rb', line 17 def initialize(from_version:, to_version:, diff:, captured_at: nil) live = Endpoint.record?(to_version) @from_version = from_version @to_version = (to_version unless live) @from_boundary = ActivityBoundary.from_version(from_version) @to_boundary = if live ActivityBoundary.current(to_version, captured_at: captured_at) else ActivityBoundary.from_version(to_version) end @diff = diff freeze end |
Instance Attribute Details
#from_boundary ⇒ ActivityBoundary (readonly)
9 10 11 |
# File 'lib/paper_trail_diff/step.rb', line 9 def from_boundary @from_boundary end |
#from_version ⇒ Object (readonly)
7 8 9 |
# File 'lib/paper_trail_diff/step.rb', line 7 def from_version @from_version end |
#to_boundary ⇒ ActivityBoundary (readonly)
10 11 12 |
# File 'lib/paper_trail_diff/step.rb', line 10 def to_boundary @to_boundary end |
#to_version ⇒ Object (readonly)
8 9 10 |
# File 'lib/paper_trail_diff/step.rb', line 8 def to_version @to_version end |
Instance Method Details
#empty? ⇒ Boolean
: () -> bool
32 33 34 |
# File 'lib/paper_trail_diff/step.rb', line 32 def empty? diff.empty? end |
#to_h ⇒ Hash[Symbol, untyped]
: () -> Hash[Symbol, untyped]
37 38 39 40 41 42 43 44 |
# File 'lib/paper_trail_diff/step.rb', line 37 def to_h { from_version_id: from_version.id, to_version_id: to_version&.id, to_boundary: to_boundary.to_h, diff: diff.to_h } end |