Class: CDC::Core::ColumnChange
- Inherits:
-
Object
- Object
- CDC::Core::ColumnChange
- 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
- #name ⇒ String, ... readonly
- #new_value ⇒ String, ... readonly
- #old_value ⇒ String, ... readonly
Instance Method Summary collapse
-
#changed? ⇒ Boolean
Whether the old and new values differ.
-
#initialize(name:, old_value:, new_value:) ⇒ ColumnChange
constructor
Build a column-level change object.
-
#to_h ⇒ Hash{String=>Object,nil}
Convert the change into a Ractor-shareable hash.
Constructor Details
#initialize(name:, old_value:, new_value:) ⇒ ColumnChange
Build a column-level change object.
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
#name ⇒ String, ... (readonly)
14 15 16 |
# File 'lib/cdc/core/column_change.rb', line 14 def name @name end |
#new_value ⇒ String, ... (readonly)
14 15 16 |
# File 'lib/cdc/core/column_change.rb', line 14 def new_value @new_value end |
#old_value ⇒ String, ... (readonly)
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.
31 32 33 |
# File 'lib/cdc/core/column_change.rb', line 31 def changed? old_value != new_value end |
#to_h ⇒ Hash{String=>Object,nil}
Convert the change into a Ractor-shareable hash.
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 |