Class: PaperTrailDiff::ToOneAssociationDiff

Inherits:
Object
  • Object
show all
Defined in:
lib/paper_trail_diff/value_objects.rb,
sig/generated/paper_trail_diff/value_objects.rbs

Overview

Relationship and associated-record changes for belongs_to or has_one.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind:, relationship:, changed:) ⇒ ToOneAssociationDiff

: (kind: Symbol, relationship: ValueChange?, changed: RecordChange?) -> void

Parameters:



118
119
120
121
122
123
# File 'lib/paper_trail_diff/value_objects.rb', line 118

def initialize(kind:, relationship:, changed:)
  @kind = kind
  @relationship = relationship
  @changed = changed
  freeze
end

Instance Attribute Details

#changedRecordChange? (readonly)

Signature:

  • RecordChange?

Returns:



115
116
117
# File 'lib/paper_trail_diff/value_objects.rb', line 115

def changed
  @changed
end

#kindSymbol (readonly)

Signature:

  • Symbol

Returns:

  • (Symbol)


113
114
115
# File 'lib/paper_trail_diff/value_objects.rb', line 113

def kind
  @kind
end

#relationshipValueChange? (readonly)

Signature:

  • ValueChange?

Returns:



114
115
116
# File 'lib/paper_trail_diff/value_objects.rb', line 114

def relationship
  @relationship
end

Instance Method Details

#empty?Boolean

: () -> bool

Returns:

  • (Boolean)


126
127
128
# File 'lib/paper_trail_diff/value_objects.rb', line 126

def empty?
  relationship.nil? && changed.nil?
end

#to_hHash[Symbol, untyped]

: () -> Hash[Symbol, untyped]

Returns:

  • (Hash[Symbol, untyped])


131
132
133
134
135
136
137
# File 'lib/paper_trail_diff/value_objects.rb', line 131

def to_h
  {
    kind: kind,
    relationship: Support.serialize(relationship),
    changed: Support.serialize(changed)
  }
end