Class: Camping::GuideBook::ActiveRecordCloser

Inherits:
Object
  • Object
show all
Defined in:
lib/guidebook.rb

Overview

ActiveRecordCloser is middleware that closes the connection to the database.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ActiveRecordCloser

Returns a new instance of ActiveRecordCloser.



19
20
21
# File 'lib/guidebook.rb', line 19

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



23
24
25
26
27
28
# File 'lib/guidebook.rb', line 23

def call(env)
  @app.call(env)
ensure
  conn = ActiveRecord::Base.connection
  conn.close if conn.respond_to?(:close)
end