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.



4
5
6
# File 'lib/gui_debugger/middleware.rb', line 4

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



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

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

    [200, { "Content-Type" => "text/html; charset=utf-8" }, [DebugPage.show]]
  end
end