Class: ActionDispatch::Journey::Router
- Inherits:
-
Object
- Object
- ActionDispatch::Journey::Router
- Defined in:
- lib/action_dispatch/journey/router.rb,
lib/action_dispatch/journey/router/utils.rb,
lib/action_dispatch/journey/router/strexp.rb
Overview
:nodoc:
Defined Under Namespace
Classes: RoutingError, Strexp, Utils
Constant Summary collapse
- VERSION =
:nodoc:
'2.0.0'
- RouteSet =
ActionDispatch::Journey::Router
- RegexpWithNamedGroups =
ActionDispatch::Journey::Path::Pattern
Instance Attribute Summary collapse
-
#routes ⇒ Object
Returns the value of attribute routes.
Instance Method Summary collapse
-
#initialize(routes) ⇒ Router
constructor
A new instance of Router.
- #recognize(rails_req) ⇒ Object
- #serve(req) ⇒ Object
- #visualizer ⇒ Object
Constructor Details
#initialize(routes) ⇒ Router
Returns a new instance of Router.
25 26 27 |
# File 'lib/action_dispatch/journey/router.rb', line 25 def initialize(routes) @routes = routes end |
Instance Attribute Details
#routes ⇒ Object
Returns the value of attribute routes.
23 24 25 |
# File 'lib/action_dispatch/journey/router.rb', line 23 def routes @routes end |
Instance Method Details
#recognize(rails_req) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/action_dispatch/journey/router.rb', line 58 def recognize(rails_req) find_routes(rails_req).each do |match, parameters, route| unless route.path.anchored rails_req.script_name = match.to_s rails_req.path_info = match.post_match.sub(/^([^\/])/, '/\1') end yield(route, parameters) end end |
#serve(req) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/action_dispatch/journey/router.rb', line 29 def serve(req) find_routes(req).each 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 req.path_parameters = set_params.merge parameters status, headers, body = route.app.serve(req) if 'pass' == headers['X-Cascade'] req.script_name = script_name req.path_info = path_info req.path_parameters = set_params next end return [status, headers, body] end return [404, {'X-Cascade' => 'pass'}, ['Not Found']] end |
#visualizer ⇒ Object
69 70 71 72 73 74 |
# File 'lib/action_dispatch/journey/router.rb', line 69 def visualizer tt = GTG::Builder.new(ast).transition_table groups = partitioned_routes.first.map(&:ast).group_by { |a| a.to_s } asts = groups.values.map { |v| v.first } tt.visualizer(asts) end |