Class: OTR::ActiveRecord::ConnectionManagement
- Inherits:
-
Object
- Object
- OTR::ActiveRecord::ConnectionManagement
- Defined in:
- lib/otr-activerecord/middleware/connection_management.rb
Overview
Rack middleware that returns active db connections to the connection pool after a request completes.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ ConnectionManagement
constructor
A new instance of ConnectionManagement.
Constructor Details
#initialize(app) ⇒ ConnectionManagement
Returns a new instance of ConnectionManagement.
7 8 9 |
# File 'lib/otr-activerecord/middleware/connection_management.rb', line 7 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/otr-activerecord/middleware/connection_management.rb', line 11 def call(env) testing = env['rack.test'] == true resp = @app.call env resp[2] = ::Rack::BodyProxy.new resp[2] do ::ActiveRecord::Base.connection_handler.clear_active_connections! unless testing end resp rescue => e ::ActiveRecord::Base.connection_handler.clear_active_connections! unless testing raise e end |