method
recognize
v8.1.1 -
Show latest stable
- Class:
ActionDispatch::Journey::Router
recognize(req, &block)public
No documentation available.
# File actionpack/lib/action_dispatch/journey/router.rb, line 43
def recognize(req, &block)
req_params = req.path_parameters
path_info = req.path_info
script_name = req.script_name
routes = filter_routes(path_info)
custom_routes.each { |r|
routes << r if r.path.match?(path_info)
}
if req.head?
routes = match_head_routes(routes, req)
else
routes.select! { |r| r.matches?(req) }
end
if routes.size > 1
routes.sort! do |a, b|
a.precedence <=> b.precedence
end
end
routes.each do |r|
match_data = r.path.match(path_info)
path_parameters = req_params.merge r.defaults
index = 1
match_data.names.each do |name|
if val = match_data[index]
val = if val.include?("%")
CGI.unescapeURIComponent(val)
else
val
end
val.force_encoding(::Encoding::UTF_8)
path_parameters[name.to_sym] = val
end
index += 1
end
if r.path.anchored
yield(r, path_parameters)
else
req.script_name = (script_name.to_s + match_data.to_s).chomp("/")
req.path_info = match_data.post_match
req.path_info = "/" + req.path_info unless req.path_info.start_with? "/"
yield(r, path_parameters)
req.script_name = script_name
req.path_info = path_info
end
req.path_parameters = req_params
end
end