Class: Salestation::Web::ActiveRecordConnectionManagement
- Inherits:
-
Object
- Object
- Salestation::Web::ActiveRecordConnectionManagement
- Defined in:
- lib/salestation/web/active_record_connection_management.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #clear_connections ⇒ Object
-
#initialize(app) ⇒ ActiveRecordConnectionManagement
constructor
A new instance of ActiveRecordConnectionManagement.
Constructor Details
#initialize(app) ⇒ ActiveRecordConnectionManagement
Returns a new instance of ActiveRecordConnectionManagement.
6 7 8 |
# File 'lib/salestation/web/active_record_connection_management.rb', line 6 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/salestation/web/active_record_connection_management.rb', line 10 def call(env) testing = env['rack.test'] status, headers, body = @app.call(env) proxy = ::Rack::BodyProxy.new(body) do clear_connections unless testing end [status, headers, proxy] rescue Exception clear_connections unless testing raise end |
#clear_connections ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/salestation/web/active_record_connection_management.rb', line 23 def clear_connections if ActiveRecord.version >= Gem::Version.new('7.1') # For ActiveRecord 7.1 and newer. Pass :all to clear all roles, # matching AR 7.2's future default. ActiveRecord::Base.connection_handler.clear_active_connections!(:all) else # For ActiveRecord 6.1 to 7.0 ActiveRecord::Base.clear_active_connections! end end |