Class: HTM::Sinatra::Middleware
- Inherits:
-
Object
- Object
- HTM::Sinatra::Middleware
- Defined in:
- lib/htm/sinatra.rb
Overview
Rack middleware for HTM connection management
Ensures database connections are properly managed across requests.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, options = {}) ⇒ Middleware
Returns a new instance of Middleware.
94 95 96 97 |
# File 'lib/htm/sinatra.rb', line 94 def initialize(app, = {}) @app = app @options = end |
Instance Method Details
#call(env) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/htm/sinatra.rb', line 99 def call(env) # Establish connection if needed unless HTM::ActiveRecordConfig.connected? HTM::ActiveRecordConfig.establish_connection! end # Process request status, headers, body = @app.call(env) # Return response [status, headers, body] ensure # Return connections to pool ActiveRecord::Base.clear_active_connections! if defined?(ActiveRecord) end |