Class: Debezium::Change
- Inherits:
-
Object
- Object
- Debezium::Change
- Defined in:
- lib/debezium/change.rb
Overview
Represents the differences between two hashes, categorizing them as additions, removals, or modifications.
Instance Attribute Summary collapse
-
#after ⇒ Object?
readonly
The ‘after` state of the record.
-
#before ⇒ Object?
readonly
The ‘before` state of the record.
Instance Method Summary collapse
-
#added?(key) ⇒ Boolean
Checks if the provided key was added.
-
#additions ⇒ Hash{Symbol => Object] A hash where keys represent added attributes and values are the added value
Returns the list of added key-value pairs.
-
#initialize(before, after) ⇒ Change
constructor
Initializes a Change object and computes the differences between two hashes.
-
#modifications ⇒ Hash{Symbol => Array<Object>] A hash of where keys represent modified attributes
Returns the list of modified key-value pairs.
-
#modified?(key) ⇒ Boolean
Checks if the provided key was modified.
-
#removals ⇒ Hash{Symbol => Object] A hash where keys represent removed attributes and values are the previous value
Returns the list of added key-value pairs.
-
#removed?(key) ⇒ Boolean
Checks if the provided key was removed.
Constructor Details
#initialize(before, after) ⇒ Change
Initializes a Change object and computes the differences between two hashes.
16 17 18 19 |
# File 'lib/debezium/change.rb', line 16 def initialize(before, after) @before = before @after = after end |
Instance Attribute Details
#after ⇒ Object? (readonly)
7 8 9 |
# File 'lib/debezium/change.rb', line 7 def after @after end |
#before ⇒ Object? (readonly)
10 11 12 |
# File 'lib/debezium/change.rb', line 10 def before @before end |
Instance Method Details
#added?(key) ⇒ Boolean
Checks if the provided key was added.
25 26 27 |
# File 'lib/debezium/change.rb', line 25 def added?(key) additions.include?(key) end |
#additions ⇒ Hash{Symbol => Object] A hash where keys represent added attributes and values are the added value
Returns the list of added key-value pairs.
48 49 50 |
# File 'lib/debezium/change.rb', line 48 def additions @additions ||= find_additions end |
#modifications ⇒ Hash{Symbol => Array<Object>] A hash of where keys represent modified attributes
Returns the list of modified key-value pairs.
and values are a tuple of the previous and next value.
63 64 65 |
# File 'lib/debezium/change.rb', line 63 def modifications @modifications ||= find_modifications end |
#modified?(key) ⇒ Boolean
Checks if the provided key was modified.
41 42 43 |
# File 'lib/debezium/change.rb', line 41 def modified?(key) modifications.include?(key) end |
#removals ⇒ Hash{Symbol => Object] A hash where keys represent removed attributes and values are the previous value
Returns the list of added key-value pairs.
55 56 57 |
# File 'lib/debezium/change.rb', line 55 def removals @removals ||= find_removals end |
#removed?(key) ⇒ Boolean
Checks if the provided key was removed.
33 34 35 |
# File 'lib/debezium/change.rb', line 33 def removed?(key) removals.include?(key) end |