Class: Debezium::Change

Inherits:
Object
  • Object
show all
Defined in:
lib/debezium/change.rb

Overview

Represents the differences between two hashes, categorizing them as additions, removals, or modifications.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#afterObject? (readonly)



7
8
9
# File 'lib/debezium/change.rb', line 7

def after
  @after
end

#beforeObject? (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

#additionsHash{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

#modificationsHash{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

#removalsHash{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