Class: PaperTrailDiff::ActivityStep

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

Parameters:



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

#diffDiff (readonly)

Signature:

  • Diff

Returns:



110
111
112
# File 'lib/paper_trail_diff/activity_boundary.rb', line 110

def diff
  @diff
end

#from_boundaryActivityBoundary (readonly)

Signature:

  • ActivityBoundary

Returns:



108
109
110
# File 'lib/paper_trail_diff/activity_boundary.rb', line 108

def from_boundary
  @from_boundary
end

#from_snapshotRecordSnapshot? (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.

Returns:



116
117
118
# File 'lib/paper_trail_diff/activity_boundary.rb', line 116

def from_snapshot
  @from_snapshot
end

#to_boundaryActivityBoundary (readonly)

Signature:

  • ActivityBoundary

Returns:



109
110
111
# File 'lib/paper_trail_diff/activity_boundary.rb', line 109

def to_boundary
  @to_boundary
end

#to_snapshotRecordSnapshot? (readonly)

Signature:

  • RecordSnapshot?

Returns:



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

Parameters:

Returns:



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

Returns:

  • (Boolean)


144
145
146
# File 'lib/paper_trail_diff/activity_boundary.rb', line 144

def empty?
  diff.empty?
end

#to_hHash[Symbol, untyped]

: () -> Hash[Symbol, untyped]

Returns:

  • (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