Sha256: 12214095b81dab75f34b8dafccaa1b4098a48d15da04fb88f47f10de863cf336

Contents?: true

Size: 763 Bytes

Versions: 1

Compression:

Stored size: 763 Bytes

Contents

# -*- encoding: utf-8 -*-
module Contentful
  module Management
    # Utility methods used by the contentful gemend
    module Support
      class << self
        # Transforms CamelCase into snake_case (taken from zucker)
        def snakify(object)
          snake = String(object).gsub(/(?<!^)[A-Z]/) { "_#$&" }
          snake.downcase
        end

        def deep_hash_merge(hash_1, hash_2)
          hash_1.merge(hash_2) 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' ? self.deep_hash_merge(oldval, newval) : newval
          end
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
contentful-management-0.0.1.pre lib/contentful/management/support.rb