Class: ActionDispatch::Journey::Router
- Defined in:
- actionpack/lib/action_dispatch/journey/router.rb,
actionpack/lib/action_dispatch/journey/router/utils.rb
Overview
:nodoc:
Defined Under Namespace
Classes: Utils
Instance Attribute Summary collapse
-
#routes ⇒ Object
Returns the value of attribute routes.
Instance Method Summary collapse
- #eager_load! ⇒ Object
-
#initialize(routes) ⇒ Router
constructor
A new instance of Router.
- #recognize(req, &block) ⇒ Object
- #serve(req) ⇒ Object
Constructor Details
#initialize(routes) ⇒ Router
Returns a new instance of Router.
19 20 21 |
# File 'actionpack/lib/action_dispatch/journey/router.rb', line 19 def initialize(routes) @routes = routes end |
Instance Attribute Details
#routes ⇒ Object
Returns the value of attribute routes.
17 18 19 |
# File 'actionpack/lib/action_dispatch/journey/router.rb', line 17 def routes @routes end |
Instance Method Details
#eager_load! ⇒ Object
23 24 25 26 27 28 |
# File 'actionpack/lib/action_dispatch/journey/router.rb', line 23 def eager_load! # Eagerly trigger the simulator's initialization so it doesn't happen during a # request cycle. simulator nil end |
#recognize(req, &block) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# 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 |
#serve(req) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'actionpack/lib/action_dispatch/journey/router.rb', line 30 def serve(req) recognize(req) do |route, parameters| req.path_parameters = parameters req.route = route _, headers, _ = response = route.app.serve(req) return response unless headers[Constants::X_CASCADE] == "pass" end [404, { Constants::X_CASCADE => "pass" }, ["Not Found"]] end |