class Rack::Perf::NormalizePath

Public Instance Methods

path() click to toggle source
# File lib/rack/perf.rb, line 63
def path
  normalize_path
rescue ActionController::RoutingError
  nil
end
path?() click to toggle source
# File lib/rack/perf.rb, line 59
def path?
  path != nil
end

Private Instance Methods

normalize_path() click to toggle source
# File lib/rack/perf.rb, line 83
def normalize_path
  path_split = request.path.split(/\//)
  format     = params["format"].to_s

  normalized_path = path_split.map do |path_part|
    params.each do |param, path_value|
      part_equals_value = path_part == path_value
      part_equals_value_with_format = format && path_part == ("%s.%s" % [path_value, format])

      if part_equals_value || part_equals_value_with_format
        path_part = ":%s" % param.to_s
      end
    end

    path_part
  end

  normalized_path.join("/")
end
params() click to toggle source
# File lib/rack/perf.rb, line 75
def params
  params = {}

  route
    .reject { |param, value| ["controller", "action"].include?(param.to_s) }
    .each   { |param, value| params[param.to_s] = value }
end
route() click to toggle source
# File lib/rack/perf.rb, line 71
def route
  Rails.application.routes.recognize_path(request.path, method: request.request_method)
end