未验证 提交 f0de4734 编写于 作者: R Ryuta Kamizono 提交者: GitHub

Merge pull request #39903 from composerinteralia/fewer-passes-through-ast

Consolidate passes through path ast
......@@ -128,9 +128,19 @@ def initialize(set:, ast:, controller:, default_action:, to:, formatted:, via:,
@internal = options.delete(:internal)
@scope_options = scope_params[:options]
path_params = ast.find_all(&:symbol?).map(&:to_sym)
path_params = []
wildcard_options = {}
ast.each do |node|
if node.symbol?
path_params << node.to_sym
elsif formatted != false && node.star?
# Add a constraint for wildcard route to make it non-greedy and match the
# optional format part of the route by default.
wildcard_options[node.name.to_sym] ||= /.+?/
end
end
options = add_wildcard_options(options, formatted, ast)
options = wildcard_options.merge!(options)
options = normalize_options!(options, path_params, scope_params[:module])
......@@ -233,18 +243,6 @@ def intern(object)
object.is_a?(String) ? -object : object
end
def add_wildcard_options(options, formatted, 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 formatted != false
path_ast.grep(Journey::Nodes::Star).each_with_object({}) { |node, hash|
hash[node.name.to_sym] ||= /.+?/
}.merge options
else
options
end
end
def normalize_options!(options, path_params, modyoule)
if path_params.include?(:controller)
raise ArgumentError, ":controller segment is not allowed within a namespace block" if modyoule
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册