Sha256: 5fd45855b4f659091cc2f311e873924d0fe6b3f1f28df6028581fd8702f73da1

Contents?: true

Size: 754 Bytes

Versions: 10

Compression:

Stored size: 754 Bytes

Contents

module Fozzie
  module Rack
    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

10 entries across 10 versions & 1 rubygems

Version Path
fozzie-0.0.15 lib/fozzie/rack/middleware.rb
fozzie-0.0.14 lib/fozzie/rack/middleware.rb
fozzie-0.0.13 lib/fozzie/rack/middleware.rb
fozzie-0.0.12 lib/fozzie/rack/middleware.rb
fozzie-0.0.11 lib/fozzie/rack/middleware.rb
fozzie-0.0.10 lib/fozzie/rack/middleware.rb
fozzie-0.0.9 lib/fozzie/rack/middleware.rb
fozzie-0.0.8 lib/fozzie/rack/middleware.rb
fozzie-0.0.7 lib/fozzie/rack/middleware.rb
fozzie-0.0.6 lib/fozzie/rack/middleware.rb