Sha256: d8d602a4ac15a0d746026da5eedc688ff79449e86e2db48ec66aec47aa95b0e9

Contents?: true

Size: 832 Bytes

Versions: 3

Compression:

Stored size: 832 Bytes

Contents

# -*- encoding: utf-8 -*-
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.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
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
contentful-management-0.2.1 lib/contentful/management/support.rb
contentful-management-0.2.0 lib/contentful/management/support.rb
contentful-management-0.1.0 lib/contentful/management/support.rb