lib/grover/utils.rb in grover-0.14.2 vs lib/grover/utils.rb in grover-1.0.0
- old
+ new
@@ -4,11 +4,13 @@
#
# Utility class for Grover helper methods
#
class Utils
ACRONYMS = {
- 'css' => 'CSS'
+ 'css' => 'CSS',
+ 'csp' => 'CSP',
+ 'http' => 'HTTP'
}.freeze
private_constant :ACRONYMS
#
# Removes leading/trailing whitespaces and squishes inner whitespace with a single space
@@ -39,15 +41,16 @@
# Deep transform the keys in an object (Hash/Array)
#
# Copied from active support
# @see active_support/core_ext/hash/keys.rb
#
- def self.deep_transform_keys_in_object(object, &block)
+ def self.deep_transform_keys_in_object(object, excluding: [], &block) # rubocop:disable Metrics/MethodLength
case object
when Hash
object.each_with_object({}) do |(key, value), result|
- result[yield(key)] = deep_transform_keys_in_object(value, &block)
+ new_key = yield(key)
+ result[new_key] = excluding.include?(new_key) ? value : deep_transform_keys_in_object(value, &block)
end
when Array
object.map { |e| deep_transform_keys_in_object(e, &block) }
else
object
@@ -78,11 +81,11 @@
end
#
# Recursively normalizes hash objects with camelized string keys
#
- def self.normalize_object(object)
- deep_transform_keys_in_object(object) { |k| normalize_key(k) }
+ def self.normalize_object(object, excluding: [])
+ deep_transform_keys_in_object(object, excluding: excluding) { |k| normalize_key(k) }
end
#
# Normalizes hash keys into camelized strings, including up-casing known acronyms
#