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: {})


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

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

Signature:

  • Hash[String, ToOneAssociationDiff | CollectionAssociationDiff]

Returns:



27
28
29
# File 'lib/paper_trail_diff/value_objects.rb', line 27

def associations
  @associations
end

#attributesHash[String, ValueChange] (readonly)

Signature:

  • Hash[String, ValueChange]

Returns:



26
27
28
# File 'lib/paper_trail_diff/value_objects.rb', line 26

def attributes
  @attributes
end

#recordRecordReference (readonly)

Signature:

  • RecordReference

Returns:



25
26
27
# File 'lib/paper_trail_diff/value_objects.rb', line 25

def record
  @record
end

Instance Method Details

#to_hHash[Symbol, untyped]

: () -> Hash[Symbol, untyped]

Returns:

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