class Rack::WebProfiler
Constants
- ENV_EXCEPTION
- ENV_RUNTIME
- ENV_RUNTIME_START
Env key constants.
- VERSION
Attributes
data[R]
Public Class Methods
config()
click to toggle source
Configure the WebProfiler
.
@yield the Config
object.
@return [Rack::WebProfiler::Config]
# File lib/rack/web_profiler.rb, line 38 def config @config ||= Config.new @config.build!(&Proc.new) if block_given? @config end
data(k = nil, v = :undefined)
click to toggle source
Data container.
@param key [String, Symbol, nil] @param value
@return
# File lib/rack/web_profiler.rb, line 71 def data(k = nil, v = :undefined) @data ||= {} return @data if k === nil @data[k] = v unless v === :undefined @data[k] if @data.key?(k) end
new(app, tmp_dir: nil)
click to toggle source
Initialize.
@param app [Proc] @option tmp_dir [String]
# File lib/rack/web_profiler.rb, line 92 def initialize(app, tmp_dir: nil) @app = app WebProfiler.config.tmp_dir = tmp_dir unless tmp_dir.nil? WebProfiler.config(&Proc.new) if block_given? end
register_collector(collector_class)
click to toggle source
Register one or many collectors.
@param collector_class [Array, Class]
# File lib/rack/web_profiler.rb, line 52 def register_collector(collector_class) config.collectors.add_collector collector_class end
Also aliased as: register_collectors
reset_collectors!()
click to toggle source
Reset collectors.
# File lib/rack/web_profiler.rb, line 45 def reset_collectors! config.collectors.reset! end
reset_data!()
click to toggle source
Reset data container.
# File lib/rack/web_profiler.rb, line 81 def reset_data! @data = {} end
unregister_collector(collector_class)
click to toggle source
Unregister one or many collectors.
@param collector_class [Array, Class]
# File lib/rack/web_profiler.rb, line 60 def unregister_collector(collector_class) config.collectors.remove_collector collector_class end
Also aliased as: unregister_collectors
Public Instance Methods
call(env)
click to toggle source
Call.
@param env [Hash]
@return [Array]
# File lib/rack/web_profiler.rb, line 104 def call(env) WebProfiler.reset_data! begin request = WebProfiler::Request.new(env) env[ENV_RUNTIME_START] = Time.now.to_f response = WebProfiler::Router.response_for(request) return response.finish if response.is_a? Rack::Response status, headers, body = @app.call(env) rescue => e process(request, body, status, headers, e) raise end process(request, body, status, headers) end
Private Instance Methods
process(request, body, status, headers, exception = nil)
click to toggle source
Process the request.
@param request [Rack::WebProfiler::Request] @param body @param status [Integer] @param headers [Hash] @param exception [Exception, nil]
@return [Rack::Response]
# File lib/rack/web_profiler.rb, line 134 def process(request, body, status, headers, exception = nil) request.env[ENV_RUNTIME] = Time.now.to_f - request.env[ENV_RUNTIME_START] request.env[ENV_EXCEPTION] = nil if !exception.nil? request.env[ENV_EXCEPTION] = exception WebProfiler::Engine.process_exception(request).finish else WebProfiler::Engine.process(request, body, status, headers).finish end end