Class: PaperTrailDiff::NestedComparator

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

Overview

Compares the inside of a value a database column holds whole.

A JSON or jsonb column reifies to one Hash, so an ordinary attribute diff can only say that the blob changed. This says which keys changed, leaving the surrounding diff untouched.

Three decisions worth knowing about.

Paths are arrays, not dotted strings. A JSON key may contain a dot -- host names and locales routinely do -- and joining would make a.b ambiguous between one key and two.

Arrays are leaves. Their elements carry no identity, so an insertion at the front makes every later index look changed; reporting "element 2 changed" would be confidently wrong about a list that merely shifted. The whole array is reported as one change, which is the same rule the collection comparator follows for records it cannot identify.

An absent key is not a null one. {"a": null} and {} mean different things in JSON and an audit trail that conflated them would be lying about one of them, so absence is its own value rather than nil.

Constant Summary collapse

ABSENT =

Stands in for a key that was not there at all.

Returns:

  • (Object)
Object.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from_value, to_value) ⇒ NestedComparator

Returns a new instance of NestedComparator.

Signature:

  • (untyped, untyped) -> void



37
# File 'sig/generated/paper_trail_diff/nested_comparator.rbs', line 37

def initialize: (untyped, untyped) -> void

Class Method Details

.call(from_value, to_value) ⇒ Object

Signature:

  • (untyped, untyped) -> Hash[Array[String], ValueChange]



34
# File 'sig/generated/paper_trail_diff/nested_comparator.rbs', line 34

def self.call: (untyped, untyped) -> Hash[Array[String], ValueChange]

Instance Method Details

#callObject

Returns the changed paths, or an empty hash when the pair is not two structures this can look inside. An empty result therefore means "nothing to report at this depth", and the caller still has the whole-value change.

Signature:

  • () -> Hash[Array[String], ValueChange]



43
# File 'sig/generated/paper_trail_diff/nested_comparator.rbs', line 43

def call: () -> Hash[Array[String], ValueChange]

#inspectObject

Returns:

  • (Object)


29
# File 'sig/generated/paper_trail_diff/nested_comparator.rbs', line 29

def inspect: () -> untyped

#to_sObject

Returns:

  • (Object)


31
# File 'sig/generated/paper_trail_diff/nested_comparator.rbs', line 31

def to_s: () -> untyped