diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-14 10:39:22 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-14 10:39:33 -0700 |
commit | aaaa67902ee1d129a6907e4ebd726f383ad7002b (patch) | |
tree | f3d2f08ad0a1414316bd37f747d73350a35b2fc8 | |
parent | 7fa6600b52b7477a958473d504415b7610d39b34 (diff) | |
download | rails-aaaa67902ee1d129a6907e4ebd726f383ad7002b.tar.gz rails-aaaa67902ee1d129a6907e4ebd726f383ad7002b.tar.bz2 rails-aaaa67902ee1d129a6907e4ebd726f383ad7002b.zip |
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
-rw-r--r-- | actionpack/lib/action_dispatch/journey/parser_extras.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 16 | ||||
-rw-r--r-- | actionpack/test/dispatch/mapper_test.rb | 3 |
3 files changed, 12 insertions, 11 deletions
diff --git a/actionpack/lib/action_dispatch/journey/parser_extras.rb b/actionpack/lib/action_dispatch/journey/parser_extras.rb index 14892f4321..fff0299812 100644 --- a/actionpack/lib/action_dispatch/journey/parser_extras.rb +++ b/actionpack/lib/action_dispatch/journey/parser_extras.rb @@ -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 diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 51d4ebb5c4..98c17c6dbb 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -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 diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 4155a44c39..0c506a13bf 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -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 |