Class: Whodunit::Chronicles::StreamAdapter
- Inherits:
-
Object
- Object
- Whodunit::Chronicles::StreamAdapter
- Defined in:
- lib/whodunit/chronicles/stream_adapter.rb
Overview
Abstract base class for database streaming adapters
Defines the interface that all database-specific adapters must implement for streaming database changes into audit events.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#position ⇒ Object
writeonly
protected
Sets the attribute position.
-
#running ⇒ Object
writeonly
protected
Sets the attribute running.
Instance Method Summary collapse
-
#current_position ⇒ String?
Get current replication position.
-
#initialize(logger: Chronicles.logger) ⇒ StreamAdapter
constructor
A new instance of StreamAdapter.
-
#log(level, message, context = {}) ⇒ Object
protected
Log a message with context.
-
#setup ⇒ void
Set up the database for streaming (create publications, slots, etc.).
-
#start_streaming ⇒ void
Start streaming database changes.
-
#stop_streaming ⇒ void
Stop streaming database changes.
-
#streaming? ⇒ Boolean
Check if adapter is currently streaming.
-
#teardown ⇒ void
Tear down streaming setup (remove publications, slots, etc.).
-
#test_connection ⇒ Boolean
Test connection to the database.
Constructor Details
#initialize(logger: Chronicles.logger) ⇒ StreamAdapter
Returns a new instance of StreamAdapter.
12 13 14 15 16 |
# File 'lib/whodunit/chronicles/stream_adapter.rb', line 12 def initialize(logger: Chronicles.logger) @logger = logger @running = false @position = nil end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
10 11 12 |
# File 'lib/whodunit/chronicles/stream_adapter.rb', line 10 def logger @logger end |
#position=(value) ⇒ Object (writeonly, protected)
Sets the attribute position
76 77 78 |
# File 'lib/whodunit/chronicles/stream_adapter.rb', line 76 def position=(value) @position = value end |
#running=(value) ⇒ Object (writeonly, protected)
Sets the attribute running
76 77 78 |
# File 'lib/whodunit/chronicles/stream_adapter.rb', line 76 def running=(value) @running = value end |
Instance Method Details
#current_position ⇒ String?
Get current replication position
39 40 41 |
# File 'lib/whodunit/chronicles/stream_adapter.rb', line 39 def current_position raise NotImplementedError, "#{self.class} must implement #current_position" end |
#log(level, message, context = {}) ⇒ Object (protected)
Log a message with context
83 84 85 86 87 88 |
# File 'lib/whodunit/chronicles/stream_adapter.rb', line 83 def log(level, , context = {}) logger.public_send(level, , adapter: self.class.name.split('::').last, position: current_position, **context) end |
#setup ⇒ void
This method returns an undefined value.
Set up the database for streaming (create publications, slots, etc.)
54 55 56 |
# File 'lib/whodunit/chronicles/stream_adapter.rb', line 54 def setup raise NotImplementedError, "#{self.class} must implement #setup" end |
#start_streaming ⇒ void
This method returns an undefined value.
Start streaming database changes
23 24 25 |
# File 'lib/whodunit/chronicles/stream_adapter.rb', line 23 def start_streaming(&) raise NotImplementedError, "#{self.class} must implement #start_streaming" end |
#stop_streaming ⇒ void
This method returns an undefined value.
Stop streaming database changes
31 32 33 |
# File 'lib/whodunit/chronicles/stream_adapter.rb', line 31 def stop_streaming raise NotImplementedError, "#{self.class} must implement #stop_streaming" end |
#streaming? ⇒ Boolean
Check if adapter is currently streaming
46 47 48 |
# File 'lib/whodunit/chronicles/stream_adapter.rb', line 46 def streaming? @running end |
#teardown ⇒ void
This method returns an undefined value.
Tear down streaming setup (remove publications, slots, etc.)
62 63 64 |
# File 'lib/whodunit/chronicles/stream_adapter.rb', line 62 def teardown raise NotImplementedError, "#{self.class} must implement #teardown" end |
#test_connection ⇒ Boolean
Test connection to the database
70 71 72 |
# File 'lib/whodunit/chronicles/stream_adapter.rb', line 70 def test_connection raise NotImplementedError, "#{self.class} must implement #test_connection" end |