diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-14 10:54:04 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-14 10:54:04 -0700 |
commit | 4a591ce2f81d4ff56bad4b483fcc7ebbe9c0dd09 (patch) | |
tree | 6f31e17f2f8507109f58a3c5cfebd004fccd16fb /actionpack/lib/action_dispatch/routing | |
parent | b592c5b607e4879c0b603bf636cf6d11e9f4b8d2 (diff) | |
download | rails-4a591ce2f81d4ff56bad4b483fcc7ebbe9c0dd09.tar.gz rails-4a591ce2f81d4ff56bad4b483fcc7ebbe9c0dd09.tar.bz2 rails-4a591ce2f81d4ff56bad4b483fcc7ebbe9c0dd09.zip |
extract method on wildcard path parameter handling
Diffstat (limited to 'actionpack/lib/action_dispatch/routing')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 40b10d33e9..aa3fcf335b 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -108,7 +108,9 @@ module ActionDispatch path_params = path_params ast - options = normalize_options!(options, formatted, path_params, ast, modyoule) + options = add_wildcard_options(options, formatted, ast) + + options = normalize_options!(options, path_params, modyoule) split_options = constraints(options, path_params) @@ -144,16 +146,19 @@ module ActionDispatch end private - - def normalize_options!(options, formatted, path_params, path_ast, modyoule) + 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) do |node| - options[node.name.to_sym] ||= /.+?/ - end + 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 |