Class: StackProf::Remote::Middleware

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

Overview

Middleware is a simple Rack middleware that handles requests to urls matching /__stackprof__ for starting/stopping a profile session and retreiving the dump files. It delegates to the ProcessReportCollector to do the actual work of collecting and combining the dumps.

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Middleware

Returns a new instance of Middleware.



24
25
26
27
28
29
# File 'lib/stackprof/remote/middleware.rb', line 24

def initialize(app, options = {})
  @app       = app
  self.class.logger   = options.delete(:logger) || Logger.new(STDOUT)
  self.class.options  = options
  logger.info "[stackprof] Stackprof Middleware enabled"
end

Class Attribute Details

.enabledObject

Returns the value of attribute enabled.



13
14
15
# File 'lib/stackprof/remote/middleware.rb', line 13

def enabled
  @enabled
end

.loggerObject

Returns the value of attribute logger.



13
14
15
# File 'lib/stackprof/remote/middleware.rb', line 13

def logger
  @logger
end

.optionsObject

Returns the value of attribute options.



13
14
15
# File 'lib/stackprof/remote/middleware.rb', line 13

def options
  @options
end

Class Method Details

.enabled?(env) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
# File 'lib/stackprof/remote/middleware.rb', line 15

def enabled?(env)
  if enabled.respond_to?(:call)
    enabled.call(env)
  else
    enabled
  end
end

Instance Method Details

#call(env) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/stackprof/remote/middleware.rb', line 31

def call(env)
  path = env['PATH_INFO']
  if in_stackprof?(path)
    handle_stackprof(path)
  else
    @app.call(env)
  end
end