1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

pull up path parsing

`add_route` needs the AST, so rather than shove it in a hash and delete
later, lets move parsing up the stack so we can pass down later
This commit is contained in:
Aaron Patterson 2015-08-14 10:39:22 -07:00
parent 7fa6600b52
commit aaaa67902e
3 changed files with 12 additions and 11 deletions

View file

@ -6,6 +6,10 @@ module ActionDispatch
class Parser < Racc::Parser # :nodoc:
include Journey::Nodes
def self.parse(string)
new.parse string
end
def initialize
@scanner = Scanner.new
end

View file

@ -61,13 +61,13 @@ module ActionDispatch
attr_reader :requirements, :conditions, :defaults
attr_reader :to, :default_controller, :default_action
def self.build(scope, set, path, controller, default_action, to, via, formatted, options_constraints, options)
def self.build(scope, set, ast, controller, default_action, to, via, formatted, options_constraints, options)
options = scope[:options].merge(options) if scope[:options]
defaults = (scope[:defaults] || {}).dup
scope_constraints = scope[:constraints] || {}
new set, path, defaults, controller, default_action, scope[:module], to, formatted, scope_constraints, scope[:blocks] || [], via, options_constraints, options
new set, ast, defaults, controller, default_action, scope[:module], to, formatted, scope_constraints, scope[:blocks] || [], via, options_constraints, options
end
def self.check_via(via)
@ -98,7 +98,7 @@ module ActionDispatch
format != false && !path.include?(':format') && !path.end_with?('/')
end
def initialize(set, path, defaults, controller, default_action, modyoule, to, formatted, scope_constraints, blocks, via, options_constraints, options)
def initialize(set, ast, defaults, controller, default_action, modyoule, to, formatted, scope_constraints, blocks, via, options_constraints, options)
@defaults = defaults
@set = set
@ -106,7 +106,6 @@ module ActionDispatch
@default_controller = controller
@default_action = default_action
ast = path_ast path
path_params = path_params ast
options = normalize_options!(options, formatted, path_params, ast, modyoule)
@ -306,11 +305,6 @@ module ActionDispatch
ast.grep(Journey::Nodes::Symbol).map { |n| n.name.to_sym }
end
def path_ast(path)
parser = Journey::Parser.new
parser.parse path
end
def dispatcher(raise_on_name_error)
@set.dispatcher raise_on_name_error
end
@ -1607,7 +1601,9 @@ module ActionDispatch
end
path = Mapping.normalize_path URI.parser.escape(path), formatted
mapping = Mapping.build(@scope, @set, path, controller, default_action, to, via, formatted, options_constraints, options)
ast = Journey::Parser.parse path
mapping = Mapping.build(@scope, @set, ast, controller, default_action, to, via, formatted, options_constraints, options)
app, conditions, requirements, defaults = mapping.to_route
@set.add_route(app, conditions, requirements, defaults, as, anchor)
end

View file

@ -98,7 +98,8 @@ module ActionDispatch
def test_mapping_requirements
options = { }
scope = Mapper::Scope.new({})
m = Mapper::Mapping.build(scope, FakeSet.new, '/store/:name(*rest)', 'foo', 'bar', nil, [:get], nil, {}, options)
ast = Journey::Parser.parse '/store/:name(*rest)'
m = Mapper::Mapping.build(scope, FakeSet.new, ast, 'foo', 'bar', nil, [:get], nil, {}, options)
_, _, requirements, _ = m.to_route
assert_equal(/.+?/, requirements[:rest])
end