Class: ViewComponentDevtools::Middleware
- Inherits:
-
Object
- Object
- ViewComponentDevtools::Middleware
- Defined in:
- lib/view_component_devtools/middleware.rb
Instance Method Summary collapse
- #call(environment) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
7 8 9 |
# File 'lib/view_component_devtools/middleware.rb', line 7 def initialize(app) @app = app end |
Instance Method Details
#call(environment) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/view_component_devtools/middleware.rb', line 11 def call(environment) return app.call(environment) unless ViewComponentDevtools.capture_enabled? State.start!(request_id: environment["action_dispatch.request_id"] || environment["HTTP_X_REQUEST_ID"]) completed = false begin status, headers, body = app.call(environment) response = [status, headers, Rack::BodyProxy.new(body) { State.reset! }] completed = true response ensure State.reset! unless completed end end |