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
30 31 32 33 34 35 |
# File 'lib/paper_trail_diff/value_objects.rb', line 30 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)
27 28 29 |
# File 'lib/paper_trail_diff/value_objects.rb', line 27 def associations @associations end |
#attributes ⇒ Hash[String, ValueChange] (readonly)
26 27 28 |
# File 'lib/paper_trail_diff/value_objects.rb', line 26 def attributes @attributes end |
#record ⇒ RecordReference (readonly)
25 26 27 |
# File 'lib/paper_trail_diff/value_objects.rb', line 25 def record @record end |
Instance Method Details
#to_h ⇒ Hash[Symbol, untyped]
: () -> Hash[Symbol, untyped]
38 39 40 41 42 |
# File 'lib/paper_trail_diff/value_objects.rb', line 38 def to_h value = { record: Support.serialize(record), attributes: Support.serialize(attributes) } value[:associations] = Support.serialize(associations) unless associations.empty? value end |