reuse the ast we already made
This commit is contained in:
parent
3a102a58f4
commit
ffbe1b18c2
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user