Class: ActionDispatch::Journey::Router
- Defined in:
- actionpack/lib/action_dispatch/journey/router.rb,
actionpack/lib/action_dispatch/journey/router/utils.rb more...
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(rails_req) ⇒ Object
- #serve(req) ⇒ Object
- #visualizer ⇒ Object
Constructor Details
permalink #initialize(routes) ⇒ Router
Returns a new instance of Router.
22 23 24 |
# File 'actionpack/lib/action_dispatch/journey/router.rb', line 22 def initialize(routes) @routes = routes end |
Instance Attribute Details
Instance Method Details
permalink #eager_load! ⇒ Object
[View source]
26 27 28 29 30 31 |
# File 'actionpack/lib/action_dispatch/journey/router.rb', line 26 def eager_load! # Eagerly trigger the simulator's initialization so it doesn't happen during a # request cycle. simulator nil end |
permalink #recognize(rails_req) ⇒ Object
[View source]
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'actionpack/lib/action_dispatch/journey/router.rb', line 68 def recognize(rails_req) find_routes(rails_req) do |match, parameters, route| unless route.path.anchored rails_req.script_name = match.to_s rails_req.path_info = match.post_match rails_req.path_info = "/" + rails_req.path_info unless rails_req.path_info.start_with? "/" end parameters = route.defaults.merge parameters yield(route, parameters) end end |
permalink #serve(req) ⇒ Object
[View source]
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'actionpack/lib/action_dispatch/journey/router.rb', line 33 def serve(req) find_routes(req) do |match, parameters, route| set_params = req.path_parameters path_info = req.path_info script_name = req.script_name unless route.path.anchored req.script_name = (script_name.to_s + match.to_s).chomp("/") req.path_info = match.post_match req.path_info = "/" + req.path_info unless req.path_info.start_with? "/" end tmp_params = set_params.merge route.defaults parameters.each_pair { |key, val| tmp_params[key] = val.force_encoding(::Encoding::UTF_8) } req.path_parameters = tmp_params req.route_uri_pattern = route.path.spec.to_s _, headers, _ = response = route.app.serve(req) if "pass" == headers[Constants::X_CASCADE] req.script_name = script_name req.path_info = path_info req.path_parameters = set_params next end return response end [404, { Constants::X_CASCADE => "pass" }, ["Not Found"]] end |
permalink #visualizer ⇒ Object
[View source]
81 82 83 84 85 86 |
# File 'actionpack/lib/action_dispatch/journey/router.rb', line 81 def visualizer tt = GTG::Builder.new(ast).transition_table groups = partitioned_routes.first.map(&:ast).group_by(&:to_s) asts = groups.values.map(&:first) tt.visualizer(asts) end |