Class: PaperTrailDiff::Diff
- Inherits:
-
Object
- Object
- PaperTrailDiff::Diff
- Defined in:
- lib/paper_trail_diff/traversal.rb,
lib/paper_trail_diff/value_objects.rb,
sig/generated/paper_trail_diff/traversal.rbs,
sig/generated/paper_trail_diff/value_objects.rbs
Overview
The complete structured difference between two normalized endpoints.
Instance Attribute Summary collapse
- #associations ⇒ Hash[String, ToOneAssociationDiff | CollectionAssociationDiff] readonly
- #attributes ⇒ Hash[String, ValueChange] readonly
- #record_presence_change ⇒ ValueChange? readonly
Instance Method Summary collapse
-
#each_change {|arg0| ... } ⇒ Object
Walks only semantic changes, excluding snapshot state included for context.
-
#each_entry {|arg0| ... } ⇒ Object
Walks semantic changes and the nested state carried by added or removed records.
-
#empty? ⇒ Boolean
: () -> bool.
-
#initialize(record_presence_change: nil, attributes: {}, associations: {}) ⇒ Diff
constructor
: (?record_presence_change: ValueChange?, ?attributes: attribute_changes, ?associations: association_diffs) -> void.
-
#to_h ⇒ Hash[Symbol, untyped]
: () -> Hash[Symbol, untyped].
Constructor Details
#initialize(record_presence_change: nil, attributes: {}, associations: {}) ⇒ Diff
: (?record_presence_change: ValueChange?, ?attributes: attribute_changes, ?associations: association_diffs) -> void
113 114 115 116 117 118 |
# File 'lib/paper_trail_diff/value_objects.rb', line 113 def initialize(record_presence_change: nil, attributes: {}, associations: {}) @record_presence_change = record_presence_change @attributes = Support.immutable_copy(attributes) @associations = Support.immutable_copy(associations) freeze end |
Instance Attribute Details
#associations ⇒ Hash[String, ToOneAssociationDiff | CollectionAssociationDiff] (readonly)
110 111 112 |
# File 'lib/paper_trail_diff/value_objects.rb', line 110 def associations @associations end |
#attributes ⇒ Hash[String, ValueChange] (readonly)
109 110 111 |
# File 'lib/paper_trail_diff/value_objects.rb', line 109 def attributes @attributes end |
#record_presence_change ⇒ ValueChange? (readonly)
108 109 110 |
# File 'lib/paper_trail_diff/value_objects.rb', line 108 def record_presence_change @record_presence_change end |
Instance Method Details
#each_change ⇒ Diff #each_change ⇒ Enumerator[TraversalEntry, Diff]
Walks only semantic changes, excluding snapshot state included for context.
73 74 75 76 77 78 |
# File 'lib/paper_trail_diff/traversal.rb', line 73 def each_change(&receiver) return enum_for(:each_change) unless receiver each_entry { |entry| receiver.call(entry) if entry.change? } self end |
#each_entry ⇒ Diff #each_entry ⇒ Enumerator[TraversalEntry, Diff]
Walks semantic changes and the nested state carried by added or removed records.
63 64 65 66 67 68 |
# File 'lib/paper_trail_diff/traversal.rb', line 63 def each_entry(&receiver) return enum_for(:each_entry) unless receiver DiffTraversal.new(self, receiver).call self end |
#empty? ⇒ Boolean
: () -> bool
121 122 123 |
# File 'lib/paper_trail_diff/value_objects.rb', line 121 def empty? record_presence_change.nil? && attributes.empty? && associations.empty? end |
#to_h ⇒ Hash[Symbol, untyped]
: () -> Hash[Symbol, untyped]
126 127 128 129 130 131 132 |
# File 'lib/paper_trail_diff/value_objects.rb', line 126 def to_h { record_presence_change: Support.serialize(record_presence_change), attributes: Support.serialize(attributes), associations: Support.serialize(associations) } end |