Class: PaperTrailDiff::RecordChange
- Inherits:
-
Object
- Object
- PaperTrailDiff::RecordChange
- Defined in:
- lib/paper_trail_diff/value_objects.rb,
sig/generated/paper_trail_diff/value_objects.rbs
Overview
Attribute and nested-association changes for a record whose identity did not change.
Instance Attribute Summary collapse
- #associations ⇒ Hash[String, ToOneAssociationDiff | CollectionAssociationDiff] readonly
- #attributes ⇒ Hash[String, ValueChange] readonly
- #record ⇒ RecordReference readonly
Instance Method Summary collapse
-
#initialize(record:, attributes:, associations: {}) ⇒ RecordChange
constructor
: (record: RecordSnapshot, attributes: attribute_changes, ?associations: association_diffs) -> void.
-
#to_h ⇒ Hash[Symbol, untyped]
: () -> Hash[Symbol, untyped].
Constructor Details
#initialize(record:, attributes:, associations: {}) ⇒ RecordChange
: (record: RecordSnapshot, attributes: attribute_changes, ?associations: association_diffs) -> void
96 97 98 99 100 101 |
# File 'lib/paper_trail_diff/value_objects.rb', line 96 def initialize(record:, attributes:, associations: {}) @record = record.reference @attributes = Support.immutable_copy(attributes) @associations = Support.immutable_copy(associations) freeze end |
Instance Attribute Details
#associations ⇒ Hash[String, ToOneAssociationDiff | CollectionAssociationDiff] (readonly)
93 94 95 |
# File 'lib/paper_trail_diff/value_objects.rb', line 93 def associations @associations end |
#attributes ⇒ Hash[String, ValueChange] (readonly)
92 93 94 |
# File 'lib/paper_trail_diff/value_objects.rb', line 92 def attributes @attributes end |
#record ⇒ RecordReference (readonly)
91 92 93 |
# File 'lib/paper_trail_diff/value_objects.rb', line 91 def record @record end |
Instance Method Details
#to_h ⇒ Hash[Symbol, untyped]
: () -> Hash[Symbol, untyped]
104 105 106 107 108 |
# File 'lib/paper_trail_diff/value_objects.rb', line 104 def to_h value = { record: Support.serialize(record), attributes: Support.serialize(attributes) } value[:associations] = Support.serialize(associations) unless associations.empty? value end |