Class: CDC::Core::ColumnChange

Inherits:
Object
  • Object
show all
Defined in:
lib/cdc/core/column_change.rb

Overview

Represents a single column-level value change.

ColumnChange is immutable and Ractor-shareable. Values that cannot be made shareable by Ruby are represented by their frozen #inspect string so the enclosing event can still cross Ractor boundaries safely.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, old_value:, new_value:) ⇒ ColumnChange

Build a column-level change object.

Parameters:

  • name (#to_s)

    column name

  • old_value (Object, nil)

    previous value

  • new_value (Object, nil)

    new value



21
22
23
24
25
26
# File 'lib/cdc/core/column_change.rb', line 21

def initialize(name:, old_value:, new_value:)
  @name = String(name).freeze
  @old_value = make_value_shareable(old_value)
  @new_value = make_value_shareable(new_value)
  Ractor.make_shareable(self)
end

Instance Attribute Details

#nameString, ... (readonly)

Returns:

  • (String)

    column name

  • (Object, nil)

    value before the change

  • (Object, nil)

    value after the change



14
15
16
# File 'lib/cdc/core/column_change.rb', line 14

def name
  @name
end

#new_valueString, ... (readonly)

Returns:

  • (String)

    column name

  • (Object, nil)

    value before the change

  • (Object, nil)

    value after the change



14
15
16
# File 'lib/cdc/core/column_change.rb', line 14

def new_value
  @new_value
end

#old_valueString, ... (readonly)

Returns:

  • (String)

    column name

  • (Object, nil)

    value before the change

  • (Object, nil)

    value after the change



14
15
16
# File 'lib/cdc/core/column_change.rb', line 14

def old_value
  @old_value
end

Instance Method Details

#changed?Boolean

Whether the old and new values differ.

Returns:

  • (Boolean)


31
32
33
# File 'lib/cdc/core/column_change.rb', line 31

def changed?
  old_value != new_value
end

#to_hHash{String=>Object,nil}

Convert the change into a Ractor-shareable hash.

Returns:

  • (Hash{String=>Object,nil})


38
39
40
# File 'lib/cdc/core/column_change.rb', line 38

def to_h
  Ractor.make_shareable({ 'name' => name, 'old_value' => old_value, 'new_value' => new_value }.freeze)
end