Class: Salestation::Web::ActiveRecordConnectionManagement

Inherits:
Object
  • Object
show all
Defined in:
lib/salestation/web/active_record_connection_management.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ActiveRecordConnectionManagement

Returns a new instance of ActiveRecordConnectionManagement.



4
5
6
# File 'lib/salestation/web/active_record_connection_management.rb', line 4

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/salestation/web/active_record_connection_management.rb', line 8

def call(env)
  testing = env['rack.test']

  status, headers, body = @app.call(env)
  proxy = ::Rack::BodyProxy.new(body) do
    ActiveRecord::Base.clear_active_connections! unless testing
  end
  [status, headers, proxy]
rescue Exception
  ActiveRecord::Base.clear_active_connections! unless testing
  raise
end