Class: PaperTrailDiff::RecordChange

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(record:, attributes:, associations: {}) ⇒ RecordChange

: (record: RecordSnapshot, attributes: attribute_changes, ?associations: association_diffs) -> void

Parameters:

  • record: (RecordSnapshot)
  • attributes: (attribute_changes)
  • associations: (association_diffs) (defaults to: {})


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

#associationsHash[String, ToOneAssociationDiff | CollectionAssociationDiff] (readonly)

Signature:

  • Hash[String, ToOneAssociationDiff | CollectionAssociationDiff]

Returns:



93
94
95
# File 'lib/paper_trail_diff/value_objects.rb', line 93

def associations
  @associations
end

#attributesHash[String, ValueChange] (readonly)

Signature:

  • Hash[String, ValueChange]

Returns:



92
93
94
# File 'lib/paper_trail_diff/value_objects.rb', line 92

def attributes
  @attributes
end

#recordRecordReference (readonly)

Signature:

  • RecordReference

Returns:



91
92
93
# File 'lib/paper_trail_diff/value_objects.rb', line 91

def record
  @record
end

Instance Method Details

#to_hHash[Symbol, untyped]

: () -> Hash[Symbol, untyped]

Returns:

  • (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