Class: Fozzie::Rails::Middleware

Inherits:
Fozzie::Rack::Middleware
  • Object
show all
Defined in:
lib/fozzie/rails/middleware.rb

Overview

Time and record each request through a given Rails app This middlewware times server processing for a resource, not view render.

Instance Method Summary collapse

Instance Method Details

#generate_key(env) ⇒ Object

Generates the statistics key for the current path



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fozzie/rails/middleware.rb', line 11

def generate_key(env)
  path_str, request_method = env['PATH_INFO'], env['REQUEST_METHOD']

  return nil unless path_str

  begin
    routing = routing_lookup
    path    = routing.recognize_path(path_str, :method => request_method)
    stat    = [path[:controller], path[:action], "render"].join('.')
    stat
  rescue => exc
    S.increment "routing.error"
    nil
  end
end

#rails_versionObject



31
32
33
# File 'lib/fozzie/rails/middleware.rb', line 31

def rails_version
  ::Rails.version.to_i
end

#routing_lookupObject



27
28
29
# File 'lib/fozzie/rails/middleware.rb', line 27

def routing_lookup
  (rails_version >= 3 ? ::Rails.application.routes : ::ActionController::Routing::Routes)
end