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:



52
53
54
55
56
57
# File 'lib/paper_trail_diff/value_objects.rb', line 52

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

Instance Attribute Details

#changedRecordChange? (readonly)

Signature:

  • RecordChange?

Returns:



49
50
51
# File 'lib/paper_trail_diff/value_objects.rb', line 49

def changed
  @changed
end

#kindSymbol (readonly)

Signature:

  • Symbol

Returns:

  • (Symbol)


47
48
49
# File 'lib/paper_trail_diff/value_objects.rb', line 47

def kind
  @kind
end

#relationshipValueChange? (readonly)

Signature:

  • ValueChange?

Returns:



48
49
50
# File 'lib/paper_trail_diff/value_objects.rb', line 48

def relationship
  @relationship
end

Instance Method Details

#empty?Boolean

: () -> bool

Returns:

  • (Boolean)


60
61
62
# File 'lib/paper_trail_diff/value_objects.rb', line 60

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

#to_hHash[Symbol, untyped]

: () -> Hash[Symbol, untyped]

Returns:

  • (Hash[Symbol, untyped])


65
66
67
68
69
70
71
# File 'lib/paper_trail_diff/value_objects.rb', line 65

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