aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-05-30 10:44:07 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-06-03 11:33:50 -0700
commitf28788b2575aaf4727b95290efa603355f7c32cb (patch)
tree203ced1dff5e88113911705c52e9f4c3b2c64ca6 /actionpack
parent7a25444f182f76696ab1f0824464025a9e121f8e (diff)
downloadrails-f28788b2575aaf4727b95290efa603355f7c32cb.tar.gz
rails-f28788b2575aaf4727b95290efa603355f7c32cb.tar.bz2
rails-f28788b2575aaf4727b95290efa603355f7c32cb.zip
only look up the format option from the hash once
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb34
1 files changed, 18 insertions, 16 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 3bc578b379..a05aa9a838 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -75,13 +75,15 @@ module ActionDispatch
@default_controller = options[:controller] || scope[:controller]
@default_action = options[:action] || scope[:action]
- path = normalize_path! path, options[:format]
+ formatted = options[:format]
+
+ path = normalize_path! path, formatted
ast = path_ast path
path_params = path_params ast
- @options = normalize_options!(options, path_params, ast)
- normalize_requirements!(path_params)
+ @options = normalize_options!(options, formatted, path_params, ast)
+ normalize_requirements!(path_params, formatted)
normalize_conditions!(path_params, path, ast)
- normalize_defaults!
+ normalize_defaults!(formatted)
end
def to_route
@@ -106,10 +108,10 @@ module ActionDispatch
format != false && !path.include?(':format') && !path.end_with?('/')
end
- def normalize_options!(options, path_params, path_ast)
+ def normalize_options!(options, formatted, 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 options[:format] != false
+ if formatted != false
path_ast.grep(Journey::Nodes::Star) do |node|
options[node.name.to_sym] ||= /.+?/
end
@@ -132,19 +134,19 @@ module ActionDispatch
end
end
- def normalize_requirements!(path_params)
+ def normalize_requirements!(path_params, formatted)
constraints.each do |key, requirement|
next unless path_params.include?(key) || key == :controller
verify_regexp_requirement(requirement) if requirement.is_a?(Regexp)
@requirements[key] = requirement
end
- if options[:format] == true
+ if formatted == true
@requirements[:format] ||= /.+/
- elsif Regexp === options[:format]
- @requirements[:format] = options[:format]
- elsif String === options[:format]
- @requirements[:format] = Regexp.compile(options[:format])
+ elsif Regexp === formatted
+ @requirements[:format] = formatted
+ elsif String === formatted
+ @requirements[:format] = Regexp.compile(formatted)
end
end
@@ -158,7 +160,7 @@ module ActionDispatch
end
end
- def normalize_defaults!
+ def normalize_defaults!(formatted)
@defaults.merge!(scope[:defaults]) if scope[:defaults]
@defaults.merge!(options[:defaults]) if options[:defaults]
@@ -178,10 +180,10 @@ module ActionDispatch
verify_callable_constraint(options[:constraints])
end
- if Regexp === options[:format]
+ if Regexp === formatted
@defaults[:format] = nil
- elsif String === options[:format]
- @defaults[:format] = options[:format]
+ elsif String === formatted
+ @defaults[:format] = formatted
end
end