Class: Plumbo::Middleware

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

Overview

Rack middleware that, when enabled (development by default), watches a request’s render events and adds the Plumbo panel to the response.

Every response that rendered app files carries an X-Plumbo-Files header (the file list, with Stimulus controllers nested in). Full HTML pages also get the panel injected before </body> for the initial render. The client reads the header on every fetch — so Turbo Drive, Frame, and Stream navigations, and even custom fetch-based panes, all refresh the panel without a full reload. Requests that rendered nothing pass through untouched. Whether/how to rewrite the body lives in Injection so its checks read request state.

Defined Under Namespace

Classes: Injection

Constant Summary collapse

HEADER =
"X-Plumbo-Files"

Instance Method Summary collapse

Constructor Details

#initialize(app, config = nil) ⇒ Middleware

Returns a new instance of Middleware.



19
20
21
22
# File 'lib/plumbo/middleware.rb', line 19

def initialize(app, config = nil)
  @app = app
  @config = config
end

Instance Method Details

#call(env) ⇒ Object

:reek:DuplicateMethodCall — the disabled passthrough and the instrumented path are intentionally distinct calls into the downstream app.



26
27
28
29
30
31
32
# File 'lib/plumbo/middleware.rb', line 26

def call(env)
  return @app.call(env) unless config.enabled

  collector = Collector.new(config)
  triple = collector.collect { @app.call(env) }
  Injection.new(triple, panel_files(collector.files)).apply
end