Class: Rack::Lineprof
- Inherits:
-
Object
- Object
- Rack::Lineprof
- Defined in:
- lib/rack/lineprof.rb,
lib/rack/lineprof/sample.rb,
lib/rack/lineprof/source.rb
Defined Under Namespace
Constant Summary collapse
- CONTEXT =
0
- NOMINAL =
1
- WARNING =
2
- CRITICAL =
3
- DEFAULT_LOGGER =
if defined?(::Rails) if ::Rails.env.development? ::Logger.new(STDOUT) else ::Logger.new(::Rails.root.join('log/profiler.log')) end else ::Logger.new(STDOUT) end
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #format_profile(profile) ⇒ Object
-
#initialize(app, options = {}) ⇒ Lineprof
constructor
A new instance of Lineprof.
Constructor Details
#initialize(app, options = {}) ⇒ Lineprof
Returns a new instance of Lineprof.
27 28 29 |
# File 'lib/rack/lineprof.rb', line 27 def initialize(app, = {}) @app, @options = app, end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
25 26 27 |
# File 'lib/rack/lineprof.rb', line 25 def app @app end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
25 26 27 |
# File 'lib/rack/lineprof.rb', line 25 def @options end |
Instance Method Details
#call(env) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rack/lineprof.rb', line 31 def call(env) request = Rack::Request.new(env) matcher = request.params['lineprof'] || [:profile] logger = [:logger] || DEFAULT_LOGGER return @app.call(env) unless matcher response = nil profile = lineprof(%r{#{matcher}}) { response = @app.call(env) } logger.error Term::ANSIColor.blue("\n[Rack::Lineprof] #{'=' * 63}") + "\n\n" + format_profile(profile) + "\n" response end |