Class: PaperTrailDiff::Engine

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

Overview

Pure snapshot comparison. This class has no ActiveRecord or PaperTrail dependencies.

Class Method Summary collapse

Class Method Details

.compare(from_snapshot, to_snapshot) ⇒ Diff

: (RecordSnapshot?, RecordSnapshot?) -> Diff

Parameters:

Returns:



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/paper_trail_diff/engine.rb', line 9

def compare(from_snapshot, to_snapshot)
  return Diff.new if from_snapshot.equal?(to_snapshot)

  if from_snapshot.nil? || to_snapshot.nil?
    change = ValueChange.new(from: from_snapshot, to: to_snapshot)
    return Diff.new(record_presence_change: change)
  end

  Diff.new(
    attributes: compare_attributes(from_snapshot.attributes, to_snapshot.attributes),
    associations: compare_associations(from_snapshot.associations, to_snapshot.associations)
  )
end