Permalink
Browse files

reuse the ast we already made

  • Loading branch information...
1 parent 3a102a5 commit ffbe1b18c23b649c46e8f995cc1577ab6b7ead54 @tenderlove tenderlove committed May 29, 2014
Showing with 10 additions and 9 deletions.
  1. +10 −9 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -77,8 +77,9 @@ def initialize(set, scope, path, options)
@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 @@ def optional_format?(path, format)
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 @@ def constraints
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)

0 comments on commit ffbe1b1

Please sign in to comment.