aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-05-29 15:01:08 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-05-29 15:01:08 -0700
commitffbe1b18c23b649c46e8f995cc1577ab6b7ead54 (patch)
tree0e014ed8ea0202c70e85c69f8c65c3722e852880 /actionpack
parent3a102a58f4d33f9a8c660f617fe1242d7baa9f90 (diff)
downloadrails-ffbe1b18c23b649c46e8f995cc1577ab6b7ead54.tar.gz
rails-ffbe1b18c23b649c46e8f995cc1577ab6b7ead54.tar.bz2
rails-ffbe1b18c23b649c46e8f995cc1577ab6b7ead54.zip
reuse the ast we already made
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb19
1 files changed, 10 insertions, 9 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index ca9f00c92e..63cd2169a5 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -77,8 +77,9 @@ module ActionDispatch
@default_action = options[:action] || scope[:action]
@path = normalize_path! @path, options[:format]
- path_params = path_params @path
- @options = normalize_options!(options, path_params)
+ ast = path_ast @path
+ path_params = path_params ast
+ @options = normalize_options!(options, path_params, ast)
normalize_requirements!(path_params)
normalize_conditions!(path_params)
normalize_defaults!
@@ -107,13 +108,13 @@ module ActionDispatch
format != false && !path.include?(':format') && !path.end_with?('/')
end
- def normalize_options!(options, path_params)
- wildcards = path_ast(path).grep(Journey::Nodes::Star).map(&:name)
-
+ def normalize_options!(options, path_params, path_ast)
# Add a constraint for wildcard route to make it non-greedy and match the
# optional format part of the route by default
- if wildcards.any? && options[:format] != false
- wildcards.each { |wc| options[wc.to_sym] ||= /.+?/ }
+ if options[:format] != false
+ path_ast.grep(Journey::Nodes::Star) do |node|
+ options[node.name.to_sym] ||= /.+?/
+ end
end
if path_params.include?(:controller)
@@ -316,8 +317,8 @@ module ActionDispatch
end
end
- def path_params(path)
- path_ast(path).grep(Journey::Nodes::Symbol).map { |n| n.name.to_sym }
+ def path_params(ast)
+ ast.grep(Journey::Nodes::Symbol).map { |n| n.name.to_sym }
end
def path_ast(path)