Class: PaperTrailDiff::Analysis

Inherits:
Object
  • Object
show all
Defined in:
lib/paper_trail_diff/analysis.rb,
sig/generated/paper_trail_diff/analysis.rbs

Overview

Endpoint and root-checkpoint timeline results built from one normalized history.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(diff:, timeline:, activity_timeline: nil, from_snapshot: nil, to_snapshot: nil) ⇒ Analysis

The reconstructed states the diff was taken between. A report that has to render unchanged columns needs the whole final state, not only what moved. : (diff: Diff, timeline: Array, ?activity_timeline: Array?, ?from_snapshot: RecordSnapshot?, ?to_snapshot: RecordSnapshot?) -> void

Parameters:



25
26
27
28
29
30
31
32
# File 'lib/paper_trail_diff/analysis.rb', line 25

def initialize(diff:, timeline:, activity_timeline: nil, from_snapshot: nil, to_snapshot: nil)
  @diff = diff
  @timeline = timeline.dup.freeze
  @activity_timeline = activity_timeline&.dup&.freeze
  @from_snapshot = from_snapshot
  @to_snapshot = to_snapshot
  freeze
end

Instance Attribute Details

#activity_timelineArray[ActivityStep]? (readonly)

Signature:

  • Array[ActivityStep]?

Returns:



9
10
11
# File 'lib/paper_trail_diff/analysis.rb', line 9

def activity_timeline
  @activity_timeline
end

#diffDiff (readonly)

Signature:

  • Diff

Returns:



7
8
9
# File 'lib/paper_trail_diff/analysis.rb', line 7

def diff
  @diff
end

#from_snapshotRecordSnapshot? (readonly)

Signature:

  • RecordSnapshot?

Returns:



10
11
12
# File 'lib/paper_trail_diff/analysis.rb', line 10

def from_snapshot
  @from_snapshot
end

#timelineArray[Step] (readonly)

Signature:

  • Array[Step]

Returns:



8
9
10
# File 'lib/paper_trail_diff/analysis.rb', line 8

def timeline
  @timeline
end

#to_snapshotRecordSnapshot? (readonly)

Signature:

  • RecordSnapshot?

Returns:



11
12
13
# File 'lib/paper_trail_diff/analysis.rb', line 11

def to_snapshot
  @to_snapshot
end

Class Method Details

.emptyAnalysis

The result for a record whose requested history contains no versions, which is an empty history rather than a failed request. : () -> Analysis

Returns:



16
17
18
19
20
# File 'lib/paper_trail_diff/analysis.rb', line 16

def self.empty
  timeline = [] #: Array[Step]
  activity_timeline = [] #: Array[ActivityStep]
  new(diff: Diff.new, timeline: timeline, activity_timeline: activity_timeline)
end

Instance Method Details

#to_h(snapshots: false) ⇒ Hash[Symbol, untyped]

Reconstructed endpoint states are opt-in, because they carry the whole selected graph whether or not anything changed, which dwarfs the rest of the payload for a wide graph. : (?snapshots: bool) -> Hash[Symbol, untyped]

Parameters:

  • snapshots: (Boolean) (defaults to: false)

Returns:

  • (Hash[Symbol, untyped])


38
39
40
41
42
43
44
45
46
47
# File 'lib/paper_trail_diff/analysis.rb', line 38

def to_h(snapshots: false)
  value = { diff: diff.to_h, timeline: Support.serialize(timeline) }
  value[:activity_timeline] = Support.serialize(activity_timeline) if activity_timeline
  return value unless snapshots

  value.merge(
    from_snapshot: Support.serialize(from_snapshot),
    to_snapshot: Support.serialize(to_snapshot)
  )
end