Class: Debezium::Message
- Inherits:
-
Object
- Object
- Debezium::Message
- Defined in:
- lib/debezium/message.rb
Overview
Message represents a Debezium message, containing information about the ‘before` and `after` states of a record.
This class parses a Debezium event message (JSON) and provides methods to determine the type of operation and access the changes between the ‘before` and `after` states in case of an update operation.
Instance Attribute Summary collapse
-
#op ⇒ Symbol
readonly
The operation type (‘:create`, `:update`, `:delete`, or `:unknown`).
Instance Method Summary collapse
-
#changes ⇒ Change
Returns the changes between the ‘before` and `after` states.
-
#create? ⇒ Boolean
Checks if the operation is a “create” operation.
-
#delete? ⇒ Boolean
Checks if the operation is a “delete” operation.
-
#initialize(json) ⇒ Message
constructor
Initializes a new Message instance by parsing the given Debezium JSON message.
-
#to_h ⇒ Hash
The parsed JSON of the event.
-
#update? ⇒ Boolean
Checks if the operation is an “update” operation.
Constructor Details
#initialize(json) ⇒ Message
Initializes a new Message instance by parsing the given Debezium JSON message.
18 19 20 21 22 |
# File 'lib/debezium/message.rb', line 18 def initialize(json) @json = JSON.parse(json) @payload = @json['payload'] @op = parse_op end |
Instance Attribute Details
#op ⇒ Symbol (readonly)
Returns The operation type (‘:create`, `:update`, `:delete`, or `:unknown`).
12 13 14 |
# File 'lib/debezium/message.rb', line 12 def op @op end |
Instance Method Details
#changes ⇒ Change
Returns the changes between the ‘before` and `after` states.
48 49 50 |
# File 'lib/debezium/message.rb', line 48 def changes @changes ||= Change.new(@payload['before'], @payload['after']) end |
#create? ⇒ Boolean
Checks if the operation is a “create” operation.
27 28 29 |
# File 'lib/debezium/message.rb', line 27 def create? @op == :create end |
#delete? ⇒ Boolean
Checks if the operation is a “delete” operation.
41 42 43 |
# File 'lib/debezium/message.rb', line 41 def delete? @op == :delete end |
#to_h ⇒ Hash
Returns The parsed JSON of the event.
53 54 55 |
# File 'lib/debezium/message.rb', line 53 def to_h @json end |
#update? ⇒ Boolean
Checks if the operation is an “update” operation.
34 35 36 |
# File 'lib/debezium/message.rb', line 34 def update? @op == :update end |