Class: ActiveRecord::ConnectionAdapters::ReadysetAdapter
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::ReadysetAdapter
- Defined in:
- lib/active_record/connection_adapters/readyset_adapter.rb
Overview
The ReadySet adapter is a proxy object that delegates all its methods to an inner PostgreSQLAdapter instance.
Constant Summary collapse
- ADAPTER_NAME =
'Readyset'.freeze
Class Method Summary collapse
-
.annotate_error(e) ⇒ void
Finds the root cause of the given error and includes the Readyset::Error module in that error’s singleton class if the root cause was a ‘PG::Error`.
- .method_missing ⇒ Object
Instance Method Summary collapse
-
#initialize(pg_conn) ⇒ ReadysetAdapter
constructor
A new instance of ReadysetAdapter.
- #method_missing ⇒ Object
Constructor Details
#initialize(pg_conn) ⇒ ReadysetAdapter
Returns a new instance of ReadysetAdapter.
40 41 42 |
# File 'lib/active_record/connection_adapters/readyset_adapter.rb', line 40 def initialize(pg_conn) @inner = pg_conn end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing ⇒ Object
44 45 46 47 48 49 |
# File 'lib/active_record/connection_adapters/readyset_adapter.rb', line 44 def method_missing(...) @inner.send(...) rescue => e self.class.annotate_error(e) raise e end |
Class Method Details
.annotate_error(e) ⇒ void
This method returns an undefined value.
Finds the root cause of the given error and includes the Readyset::Error module in that error’s singleton class if the root cause was a ‘PG::Error`. This allows us to invoke `#is_a?` on the error to determine if the error came from a connection to ReadySet.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/active_record/connection_adapters/readyset_adapter.rb', line 19 def self.annotate_error(e) if e.cause annotate_error(e.cause) else if e.is_a?(::PG::Error) e.singleton_class.instance_eval do include ::Readyset::Error end end end nil end |
.method_missing ⇒ Object
33 34 35 36 37 38 |
# File 'lib/active_record/connection_adapters/readyset_adapter.rb', line 33 def self.method_missing(...) PostgreSQLAdapter.send(...) rescue => e annotate_error(e) raise e end |