Class: Ladybug::Middleware

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



14
15
16
17
18
19
20
21
22
# File 'lib/ladybug/middleware.rb', line 14

def initialize(app)
  @app = app
  @scripts = {}

  @script_repository = ScriptRepository.new
  @debugger =
    Debugger.new(preload_paths: @script_repository.all.map(&:path))
  @object_manager = ObjectManager.new
end

Instance Method Details

#call(env) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ladybug/middleware.rb', line 24

def call(env)
  puts "Debug in Chrome: chrome-devtools://devtools/bundled/inspector.html?ws=#{env['HTTP_HOST']}"

  # For now, all websocket connections are assumed to be a debug connection
  if Faye::WebSocket.websocket?(env)
    ws = create_websocket(env)

    # Return async Rack response
    ws.rack_response
  else
    @debugger.debug do
      @app.call(env)
    end
  end
end