Class: SafeRequestTimeout::ActiveRecordHook
- Inherits:
-
Object
- Object
- SafeRequestTimeout::ActiveRecordHook
- Defined in:
- lib/safe_request_timeout/active_record_hook.rb
Defined Under Namespace
Modules: AdapterInitializer
Class Method Summary collapse
-
.add_timeout!(connection_class = nil) ⇒ void
Add the timeout hook to a connection adapter class.
Class Method Details
.add_timeout!(connection_class = nil) ⇒ void
This method returns an undefined value.
Add the timeout hook to a connection adapter class. If no class is given, then the hooks will be added to each connection adapter class the first time it is instantiated. This does not require a database connection to be established and covers every adapter in use, including applications with multiple databases.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/safe_request_timeout/active_record_hook.rb', line 18 def add_timeout!(connection_class = nil) if connection_class add_hooks(connection_class) else ::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(AdapterInitializer) # Add the hooks to any adapter that already has a live connection. if ::ActiveRecord::Base.connected? ::ActiveRecord::Base.connection_pool.with_connection do |connection| add_hooks(connection.class) end end end end |