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.



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
    ActiveRecord::Base.clear_active_connections! unless testing
  end
  [status, headers, proxy]
rescue Exception
  ActiveRecord::Base.clear_active_connections! unless testing
  raise
end