lib/contentful/management/support.rb in contentful-management-3.8.0 vs lib/contentful/management/support.rb in contentful-management-3.9.0
- old
+ new
@@ -1,21 +1,23 @@
+# frozen_string_literal: true
+
module Contentful
module Management
# Utility methods used by the contentful management gem
module Support
class << self
# Transforms CamelCase into snake_case (taken from zucker)
def snakify(object)
- snake = String(object).gsub(/(?<!^)[A-Z]/) { "_#{$&}" }
+ snake = String(object).gsub(/(?<!^)[A-Z]/) { "_#{::Regexp.last_match(0)}" }
snake.downcase
end
# Merges two hashes with recursion
def deep_hash_merge(query_hash, attribute_hash)
query_hash.merge(attribute_hash) do |_key, oldval, newval|
oldval = oldval.to_hash if oldval.respond_to?(:to_hash)
newval = newval.to_hash if newval.respond_to?(:to_hash)
- oldval.class.to_s == 'Hash' && newval.class.to_s == 'Hash' ? deep_hash_merge(oldval, newval) : newval
+ oldval.instance_of?(::Hash) && newval.instance_of?(::Hash) ? deep_hash_merge(oldval, newval) : newval
end
end
# If the query contains the :select operator, we enforce :sys properties.
# The SDK requires sys.type to function properly, but as other of our SDKs