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 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.
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) -> nested_changes
|
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: () -> nested_changes
|
#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
|