Class: GuiDebugger::Middleware

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



6
7
8
# File 'lib/gui_debugger/middleware.rb', line 6

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gui_debugger/middleware.rb', line 10

def call(env)
  if %r{\A/__gui_debugger/(?<method>\w+)(/(?<index>\d+))?(/(?<val>.+))?} =~ env["PATH_INFO"]
    data = GuiDebugger.debug_context.send(method, *[index, val].compact)
    [200, { "Content-Type" => "text/plain; charset=utf-8" }, [JSON.dump({ data: data })]]
  else
    catch(:gui_debugger) do
      return @app.call(env)
    end

    DebugPage::display
  end
end