Class: Rack::WebProfiler

Inherits:
Object
  • Object
show all
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.0".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, tmp_dir: nil) ⇒ WebProfiler

Initialize

Options Hash (tmp_dir:):

  • (String)


76
77
78
79
80
81
# File 'lib/rack/web_profiler.rb', line 76

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

#dataObject (readonly)

Returns the value of attribute data.



70
71
72
# File 'lib/rack/web_profiler.rb', line 70

def data
  @data
end

Class Method Details

.config { ... } ⇒ Rack::WebProfiler::Config

Configure the WebProfiler.

Yields:

  • the Config object.



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



56
57
58
59
60
61
62
63
# File 'lib/rack/web_profiler.rb', line 56

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



65
66
67
# File 'lib/rack/web_profiler.rb', line 65

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



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/rack/web_profiler.rb', line 88

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