Class: BrainzLab::DevTools::Middleware::DebugPanel

Inherits:
Object
  • Object
show all
Defined in:
lib/brainzlab/devtools/middleware/debug_panel.rb

Constant Summary collapse

HTML_CONTENT_TYPE =
'text/html'

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ DebugPanel

Returns a new instance of DebugPanel.



9
10
11
12
# File 'lib/brainzlab/devtools/middleware/debug_panel.rb', line 9

def initialize(app)
  @app = app
  @renderer = Renderers::DebugPanelRenderer.new
end

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/brainzlab/devtools/middleware/debug_panel.rb', line 14

def call(env)
  return @app.call(env) unless should_inject?(env)

  # Start collecting data
  Data::Collector.start_request(env)

  begin
    status, headers, body = @app.call(env)

    # Only inject into HTML responses
    if injectable_response?(status, headers)
      body = inject_panel(body, env, status, headers)
      headers = update_content_length(headers, body)
    end

    [status, headers, body]
  ensure
    Data::Collector.end_request
  end
end