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 reported by membership, not by position -- see ArrayChange. Their elements carry no identity, so an insertion at the front makes every later index look changed, and one insertion reads as several edits. What is added and removed can be answered without claiming any pairing; what cannot is the same elements in a new order, so that is named rather than passed over.

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) -> nested_changes



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

def self.call: (untyped, untyped) -> nested_changes

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:

  • () -> nested_changes



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

def call: () -> nested_changes

#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