diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-11 18:42:52 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-12 14:30:52 -0700 |
commit | 3042b71a7a2b6dfcdd0e3282b834003099cd036e (patch) | |
tree | 093233204c8751219e34e08162cbddaef82f07c5 /actionpack/lib | |
parent | fd27305782f7f02065ae841db562b313349bc52e (diff) | |
download | rails-3042b71a7a2b6dfcdd0e3282b834003099cd036e.tar.gz rails-3042b71a7a2b6dfcdd0e3282b834003099cd036e.tar.bz2 rails-3042b71a7a2b6dfcdd0e3282b834003099cd036e.zip |
make `constraints` more functional
I don't want to rely on mutating ivars. This gives me more freedom when
refactoring
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index a12f60e20d..337d5e9404 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -99,7 +99,8 @@ module ActionDispatch options = normalize_options!(options, formatted, path_params, ast, modyoule) - constraints = scope_constraints.merge constraints(options, path_params) + split_options = constraints(options, path_params) + constraints = scope_constraints.merge Hash[split_options[:constraints] || []] if options_constraints.is_a?(Hash) options_constraints.each do |key, default| @@ -117,6 +118,7 @@ module ActionDispatch normalize_format!(formatted) + @conditions[:required_defaults] = (split_options[:required_defaults] || []).map(&:first) @conditions[:path_info] = path @conditions[:parsed_path_info] = ast @@ -306,17 +308,17 @@ module ActionDispatch end def constraints(options, path_params) - constraints = {} - required_defaults = [] - options.each_pair do |key, option| + options.group_by do |key, option| if Regexp === option - constraints[key] = option + :constraints else - required_defaults << key unless path_params.include?(key) + if path_params.include?(key) + :path_params + else + :required_defaults + end end end - @conditions[:required_defaults] = required_defaults - constraints end def path_params(ast) |