Class: HTM::Sinatra::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/htm/integrations/sinatra.rb

Overview

Rack middleware for HTM connection management

Ensures database connections are properly managed across requests. With Sequel’s fiber-safe connection pooling, this is largely automatic.

Examples:

Use in Sinatra app

class MyApp < Sinatra::Base
  use HTM::Sinatra::Middleware
end

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Middleware

Returns a new instance of Middleware.



111
112
113
114
# File 'lib/htm/integrations/sinatra.rb', line 111

def initialize(app, options = {})
  @app = app
  @options = options
end

Class Method Details

.store_config!Object

Store the connection config at startup (called from register_htm)



128
129
130
131
# File 'lib/htm/integrations/sinatra.rb', line 128

def self.store_config!
  # With Sequel, connection is established globally via HTM::SequelConfig
  # No additional per-request config storage needed
end

Instance Method Details

#call(env) ⇒ Object



116
117
118
119
120
121
122
123
124
125
# File 'lib/htm/integrations/sinatra.rb', line 116

def call(env)
  # Ensure connection is available
  ensure_connection!

  # Process request
  status, headers, body = @app.call(env)

  # Return response
  [status, headers, body]
end