Class: Fozzie::Rack::Middleware
- Inherits:
-
Object
- Object
- Fozzie::Rack::Middleware
- Defined in:
- lib/fozzie/rack/middleware.rb
Overview
Time and record each request through a given Rack app This middleware times server processing for a resource, not view render.
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #call_with_timer(key, env) ⇒ Object
- #call_without_timer(env) ⇒ Object
- #generate_key(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
12 13 14 |
# File 'lib/fozzie/rack/middleware.rb', line 12 def initialize(app) @app = app end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
10 11 12 |
# File 'lib/fozzie/rack/middleware.rb', line 10 def app @app end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/fozzie/rack/middleware.rb', line 16 def call(env) k = generate_key(env) if k.nil? self.call_without_timer(env) else self.call_with_timer(k, env) end end |
#call_with_timer(key, env) ⇒ Object
29 30 31 32 33 |
# File 'lib/fozzie/rack/middleware.rb', line 29 def call_with_timer(key, env) S.time_to_do key do @app.call(env) end end |
#call_without_timer(env) ⇒ Object
25 26 27 |
# File 'lib/fozzie/rack/middleware.rb', line 25 def call_without_timer(env) @app.call(env) end |
#generate_key(env) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/fozzie/rack/middleware.rb', line 35 def generate_key(env) s = env['PATH_INFO'] return nil if s.nil? s = (s == '/' ? 'index' : s.gsub(/.(\/)./) {|m| m.gsub('/', '.') }.gsub(/\//, '').strip) (s.nil? || s.empty? ? nil : "#{s}.render") end |