From bc7e94503a3fb30d6e02898fc2d08285eb0b552b Mon Sep 17 00:00:00 2001 From: Gustavo Gutierrez Date: Fri, 17 May 2019 15:13:03 +0200 Subject: Implemented deep_transform_keys/! for ActionController::Parameters --- .../lib/action_controller/metal/strong_parameters.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index 016a633f71..6a07a73d94 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -693,6 +693,23 @@ module ActionController self end + # Returns a new ActionController::Parameters instance with the + # results of running +block+ once for every key. This includes the keys + # from the root hash and from all nested hashes and arrays. The values are unchanged. + def deep_transform_keys(&block) + new_instance_with_inherited_permitted_status( + @parameters.deep_transform_keys(&block) + ) + end + + # Returns the ActionController::Parameters instance changing its keys. + # This includes the keys from the root hash and from all nested hashes and arrays. + # The values are unchanged. + def deep_transform_keys!(&block) + @parameters.deep_transform_keys!(&block) + self + end + # Deletes a key-value pair from +Parameters+ and returns the value. If # +key+ is not found, returns +nil+ (or, with optional code block, yields # +key+ and returns the result). Cf. +#extract!+, which returns the -- cgit v1.2.3