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
179 180 181 182 183 184 |
# File 'lib/paper_trail_diff/value_objects.rb', line 179 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)
176 177 178 |
# File 'lib/paper_trail_diff/value_objects.rb', line 176 def associations @associations end |
#attributes ⇒ Hash[String, ValueChange] (readonly)
175 176 177 |
# File 'lib/paper_trail_diff/value_objects.rb', line 175 def attributes @attributes end |
#record_presence_change ⇒ ValueChange? (readonly)
174 175 176 |
# File 'lib/paper_trail_diff/value_objects.rb', line 174 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
187 188 189 |
# File 'lib/paper_trail_diff/value_objects.rb', line 187 def empty? record_presence_change.nil? && attributes.empty? && associations.empty? end |
#to_h ⇒ Hash[Symbol, untyped]
: () -> Hash[Symbol, untyped]
192 193 194 195 196 197 198 |
# File 'lib/paper_trail_diff/value_objects.rb', line 192 def to_h { record_presence_change: Support.serialize(record_presence_change), attributes: Support.serialize(attributes), associations: Support.serialize(associations) } end |