Class: Rack::WebProfiler
- Inherits:
-
Object
- Object
- Rack::WebProfiler
- Defined in:
- lib/rack/web_profiler.rb,
lib/rack/web_profiler/view.rb,
lib/rack/web_profiler/model.rb,
lib/rack/web_profiler/version.rb,
lib/rack/web_profiler/collector.rb,
lib/rack/web_profiler/controller.rb
Overview
WebProfiler
Defined Under Namespace
Modules: Rouge Classes: Collector, Collectors, Config, Controller, Engine, Model, Request, Response, Router, View
Constant Summary collapse
- ENV_RUNTIME_START =
Env key constants.
"rack_webprofiler.runtime_start".freeze
- ENV_RUNTIME =
"rack_webprofiler.runtime".freeze
- ENV_EXCEPTION =
"rack_webprofiler.exception".freeze
- VERSION =
"0.1.1".freeze
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
-
.config { ... } ⇒ Rack::WebProfiler::Config
Configure the WebProfiler.
-
.data(k = nil, v = :undefined) ⇒ Object
Data container.
-
.register_collector(collector_class) ⇒ Object
(also: register_collectors)
Register one or many collectors.
-
.reset_data! ⇒ Object
Reset data container.
-
.unregister_collector(collector_class) ⇒ Object
(also: unregister_collectors)
Unregister one or many collectors.
Instance Method Summary collapse
-
#call(env) ⇒ Array
Call.
-
#initialize(app, tmp_dir: nil) ⇒ WebProfiler
constructor
Initialize.
Constructor Details
#initialize(app, tmp_dir: nil) ⇒ WebProfiler
Initialize.
83 84 85 86 87 88 |
# File 'lib/rack/web_profiler.rb', line 83 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 |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
77 78 79 |
# File 'lib/rack/web_profiler.rb', line 77 def data @data end |
Class Method Details
.config { ... } ⇒ Rack::WebProfiler::Config
Configure the WebProfiler.
34 35 36 37 38 |
# File 'lib/rack/web_profiler.rb', line 34 def config @config ||= Config.new @config.build!(&Proc.new) if block_given? @config end |
.data(k = nil, v = :undefined) ⇒ Object
Data container.
62 63 64 65 66 67 68 69 |
# File 'lib/rack/web_profiler.rb', line 62 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 |
.register_collector(collector_class) ⇒ Object Also known as: register_collectors
Register one or many collectors.
43 44 45 |
# File 'lib/rack/web_profiler.rb', line 43 def register_collector(collector_class) config.collectors.add_collector collector_class end |
.reset_data! ⇒ Object
Reset data container.
72 73 74 |
# File 'lib/rack/web_profiler.rb', line 72 def reset_data! @data = {} end |
.unregister_collector(collector_class) ⇒ Object Also known as: unregister_collectors
Unregister one or many collectors.
51 52 53 |
# File 'lib/rack/web_profiler.rb', line 51 def unregister_collector(collector_class) config.collectors.remove_collector collector_class end |
Instance Method Details
#call(env) ⇒ Array
Call.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/rack/web_profiler.rb', line 95 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 |