Class: ActiveRecord::ConnectionAdapters::RefreshConnectionManagement

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord-refresh_connection/active_record/connection_adapters/refresh_connection_management.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RefreshConnectionManagement

Returns a new instance of RefreshConnectionManagement.



4
5
6
# File 'lib/activerecord-refresh_connection/active_record/connection_adapters/refresh_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
20
21
# File 'lib/activerecord-refresh_connection/active_record/connection_adapters/refresh_connection_management.rb', line 8

def call(env)
  testing = env.key?('rack.test')

  response = @app.call(env)
  response[2] = ::Rack::BodyProxy.new(response[2]) do
    # disconnect all connections on the connection pool
    ActiveRecord::Base.clear_all_connections! unless testing
  end

  response
rescue Exception
  ActiveRecord::Base.clear_all_connections! unless testing
  raise
end