diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-30 14:12:50 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-06-03 11:33:52 -0700 |
commit | c0fc116fb4810e487397a5c739af7b5e0ef71e14 (patch) | |
tree | 729f529ca7937a828189c46bc511cd633fd8ca11 /actionpack | |
parent | 4d3955aef459a5a303112e98f2f075753fc90e8c (diff) | |
download | rails-c0fc116fb4810e487397a5c739af7b5e0ef71e14.tar.gz rails-c0fc116fb4810e487397a5c739af7b5e0ef71e14.tar.bz2 rails-c0fc116fb4810e487397a5c739af7b5e0ef71e14.zip |
only loop through constraints once
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index afa90bda08..43b46ed0ea 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -88,9 +88,14 @@ module ActionDispatch @options = normalize_options!(options, formatted, path_params, ast, scope[:module]) - constraints = constraints(options_constraints, scope[:constraints]) + constraints = constraints(options_constraints, + scope[:constraints] || {}) normalize_requirements!(path_params, formatted, constraints) + + @conditions[:path_info] = path + @conditions[:parsed_path_info] = ast + normalize_conditions!(path_params, path, ast, via, constraints) normalize_defaults!(formatted, options_constraints) end @@ -144,10 +149,13 @@ module ActionDispatch end def normalize_requirements!(path_params, formatted, constraints) - 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 + constraints.each_pair do |key, requirement| + if path_params.include?(key) || key == :controller + verify_regexp_requirement(requirement) if requirement.is_a?(Regexp) + @requirements[key] = requirement + else + @conditions[key] = requirement + end end if formatted == true @@ -200,15 +208,6 @@ module ActionDispatch end def normalize_conditions!(path_params, path, ast, via, constraints) - @conditions[:path_info] = path - @conditions[:parsed_path_info] = ast - - constraints.each do |key, condition| - unless path_params.include?(key) || key == :controller - @conditions[key] = condition - end - end - required_defaults = [] options.each do |key, required_default| unless path_params.include?(key) || Regexp === required_default @@ -310,11 +309,8 @@ module ActionDispatch end end - def constraints(option_constraints, scope_constraints) - constraints = {} - constraints.merge!(scope_constraints) if scope_constraints - - options.each do |key, option| + def constraints(option_constraints, constraints) + options.each_pair do |key, option| constraints[key] = option if Regexp === option end |