diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-07-17 14:26:47 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-07-17 14:26:47 -0700 |
commit | e956172b8b6badb04f89593fdbe4b762924a8092 (patch) | |
tree | 7fb1f76bda446698e5a8b31f08b25f62b30291ca /actionpack/lib/action_controller | |
parent | 7779e63371d1248bce5f30ebbae43e13ee7abb6a (diff) | |
download | rails-e956172b8b6badb04f89593fdbe4b762924a8092.tar.gz rails-e956172b8b6badb04f89593fdbe4b762924a8092.tar.bz2 rails-e956172b8b6badb04f89593fdbe4b762924a8092.zip |
push is_a checks up the stack
now `hash_filter` doesn't need to know about the `Parameters` class
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/metal/strong_parameters.rb | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index 9aac94ceb0..1f10fb3bbe 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -566,20 +566,22 @@ module ActionController end def each_element(object) - if object.is_a?(Array) - object.map { |el| yield el }.compact - elsif fields_for_style?(object) - hash = object.class.new - object.each { |k,v| hash[k] = yield v } - hash - else - yield object + case object + when Array + object.grep(Parameters).map { |el| yield el }.compact + when Parameters + if fields_for_style?(object) + hash = object.class.new + object.each { |k,v| hash[k] = yield v } + hash + else + yield object + end end end def fields_for_style?(object) - object.is_a?(Parameters) && - object.to_unsafe_h.all? { |k, v| k =~ /\A-?\d+\z/ && v.is_a?(Hash) } + object.to_unsafe_h.all? { |k, v| k =~ /\A-?\d+\z/ && v.is_a?(Hash) } end def unpermitted_parameters!(params) @@ -665,9 +667,7 @@ module ActionController else # Declaration { user: :name } or { user: [:name, :age, { address: ... }] }. params[key] = each_element(value) do |element| - if element.is_a?(Parameters) - element.permit(*Array.wrap(filter[key])) - end + element.permit(*Array.wrap(filter[key])) end end end |