Class: ActiveRecord::ConnectionAdapters::ConnectionHandler
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::ConnectionHandler
- Defined in:
- lib/transaction_isolation_level.rb
Instance Method Summary collapse
-
#establish_connection_with_isolation_level_adapter_patches(*args) ⇒ Object
(also: #establish_connection)
ActiveRecord only loads the adapters actually used for connections, so we can’t patch their classes until we know which one will be loaded.
Instance Method Details
#establish_connection_with_isolation_level_adapter_patches(*args) ⇒ Object Also known as: establish_connection
ActiveRecord only loads the adapters actually used for connections, so we can’t patch their classes until we know which one will be loaded. however, the adapter classes are not statically required; they are only loaded when ActiveRecord::Base#establish_connection retrieves them from the connection spec. that has several code paths to handle different arguments but eventually uses the ConnectionHandler#establish_connection method we override here to load our patches once ActiveRecord::Base#establish_connection has loaded the class to patch.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/transaction_isolation_level.rb', line 15 def establish_connection_with_isolation_level_adapter_patches(*args) # need to explicitly trigger load of the adapter for 5.1 and above, as from that point on its # required only in establish_connection, and we don't have a way to insert our patches halfway # through that method. if (ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR > 0) || ActiveRecord::VERSION::MAJOR > 5 ConnectionSpecification::Resolver.new(Base.configurations).spec(args.last) end require 'transaction_isolation_level/adapter_patches' establish_connection_without_isolation_level_adapter_patches(*args) end |