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:



150
151
152
153
154
155
156
157
# File 'lib/paper_trail_diff/activity_boundary.rb', line 150

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:



126
127
128
# File 'lib/paper_trail_diff/activity_boundary.rb', line 126

def diff
  @diff
end

#from_boundaryActivityBoundary (readonly)

Signature:

  • ActivityBoundary

Returns:



124
125
126
# File 'lib/paper_trail_diff/activity_boundary.rb', line 124

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:



132
133
134
# File 'lib/paper_trail_diff/activity_boundary.rb', line 132

def from_snapshot
  @from_snapshot
end

#to_boundaryActivityBoundary (readonly)

Signature:

  • ActivityBoundary

Returns:



125
126
127
# File 'lib/paper_trail_diff/activity_boundary.rb', line 125

def to_boundary
  @to_boundary
end

#to_snapshotRecordSnapshot? (readonly)

Signature:

  • RecordSnapshot?

Returns:



133
134
135
# File 'lib/paper_trail_diff/activity_boundary.rb', line 133

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:



139
140
141
142
143
144
145
146
147
# File 'lib/paper_trail_diff/activity_boundary.rb', line 139

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)


160
161
162
# File 'lib/paper_trail_diff/activity_boundary.rb', line 160

def empty?
  diff.empty?
end

#to_hHash[Symbol, untyped]

: () -> Hash[Symbol, untyped]

Returns:

  • (Hash[Symbol, untyped])


165
166
167
168
169
170
171
# File 'lib/paper_trail_diff/activity_boundary.rb', line 165

def to_h
  {
    from: from_boundary.to_h,
    to: to_boundary.to_h,
    diff: diff.to_h
  }
end