Class: Compass::Middleware
- Inherits:
-
Object
- Object
- Compass::Middleware
- Defined in:
- lib/compass/middleware.rb
Overview
Rack middleware that establishes the request-scoped Compass context.
It builds the configured Compass::Context once per request and memoizes
it in the Rack env under Compass::Context::ENV_KEY, so controllers and
components reuse the same instance via Compass::Context.from(env).
It also runs per-request Compass features with that context — currently breadcrumb tracking, which uses the configured breadcrumb strategy to save breadcrumb items for requests that should be tracked.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
13 14 15 |
# File 'lib/compass/middleware.rb', line 13 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/compass/middleware.rb', line 17 def call(env) request = ActionDispatch::Request.new(env) # bearer:disable ruby_rails_sql_injection context = Compass::Context.from(env) (context, request) if should_track?(context, request) rescue => e # Silently handle errors - don't break the request Compass.logger&.error "Compass middleware error: #{e.}" ensure return @app.call(env) end |