Sha256: 3e9b327208e9dcedb6135aa8c282ccab00e387ce370f318c5889487e76fe1dda
Contents?: true
Size: 912 Bytes
Versions: 3
Compression:
Stored size: 912 Bytes
Contents
require 'fozzie' module Fozzie module Rack # Time and record each request through a given Rack app # This middleware times server processing for a resource, not view render. class Middleware attr_reader :app def initialize(app) @app = app end def call(env) k = generate_key(env) if k.nil? self.call_without_timer(env) else self.call_with_timer(k, env) end end def call_without_timer(env) @app.call(env) end def call_with_timer(key, env) S.time_to_do key do @app.call(env) end end 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 end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
fozzie-1.0.2 | lib/fozzie/rack/middleware.rb |
fozzie-1.0.1 | lib/fozzie/rack/middleware.rb |
fozzie-1.0.0 | lib/fozzie/rack/middleware.rb |