Sha256: 4ebfb454f2b55a9b86d76e4f9079146fd553d8b936e46b7a63f50038c357b049

Contents?: true

Size: 895 Bytes

Versions: 12

Compression:

Stored size: 895 Bytes

Contents

module Fozzie
  module Rack

    # Time and record each request through a given Rack app
    # This middlewware 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

12 entries across 12 versions & 1 rubygems

Version Path
fozzie-0.0.27 lib/fozzie/rack/middleware.rb
fozzie-0.0.26 lib/fozzie/rack/middleware.rb
fozzie-0.0.25 lib/fozzie/rack/middleware.rb
fozzie-0.0.24 lib/fozzie/rack/middleware.rb
fozzie-0.0.23 lib/fozzie/rack/middleware.rb
fozzie-0.0.22 lib/fozzie/rack/middleware.rb
fozzie-0.0.21 lib/fozzie/rack/middleware.rb
fozzie-0.0.20 lib/fozzie/rack/middleware.rb
fozzie-0.0.19 lib/fozzie/rack/middleware.rb
fozzie-0.0.18 lib/fozzie/rack/middleware.rb
fozzie-0.0.17 lib/fozzie/rack/middleware.rb
fozzie-0.0.16 lib/fozzie/rack/middleware.rb