Class: PaperTrailDiff::NestedComparator
- Inherits:
-
Object
- Object
- PaperTrailDiff::NestedComparator
- 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.
Object.new
Class Method Summary collapse
Instance Method Summary collapse
-
#call ⇒ Object
Returns the changed paths, or an empty hash when the pair is not two structures this can look inside.
-
#initialize(from_value, to_value) ⇒ NestedComparator
constructor
A new instance of NestedComparator.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(from_value, to_value) ⇒ NestedComparator
Returns a new instance of NestedComparator.
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
34 |
# File 'sig/generated/paper_trail_diff/nested_comparator.rbs', line 34
def self.call: (untyped, untyped) -> Hash[Array[String], ValueChange]
|
Instance Method Details
#call ⇒ Object
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.
43 |
# File 'sig/generated/paper_trail_diff/nested_comparator.rbs', line 43
def call: () -> Hash[Array[String], ValueChange]
|
#inspect ⇒ Object
29 |
# File 'sig/generated/paper_trail_diff/nested_comparator.rbs', line 29
def inspect: () -> untyped
|
#to_s ⇒ Object
31 |
# File 'sig/generated/paper_trail_diff/nested_comparator.rbs', line 31
def to_s: () -> untyped
|