Class: Compass::Breadcrumb::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/compass/breadcrumb/middleware.rb

Overview

Middleware to track breadcrumb items based on requests. It uses the configured breadcrumb strategy to save breadcrumb items for requests that should be tracked.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



11
12
13
# File 'lib/compass/breadcrumb/middleware.rb', line 11

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/compass/breadcrumb/middleware.rb', line 15

def call(env)
  @request = ActionDispatch::Request.new(env)
  context = instance_exec(&Compass.config.context)

  save_breadcrumb!(context) if should_track?(context)
rescue => e
  # Silently handle breadcrumb errors - don't break the request
  Compass.logger&.error "Breadcrumb middleware error: #{e.message}"
ensure
  return @app.call(env)
end