lib/celsius.rb in celsius-0.0.1 vs lib/celsius.rb in celsius-0.2.0

- old
+ new

@@ -1,5 +1,38 @@ require "celsius/version" +require "deep_merger" module Celsius - # Your code goes here... + require "celsius/adapter" + + def self.deep_clone(object) + Marshal.load(Marshal.dump(object)) + end + + def self.deep_merge!(destination, source, options = {}) + DeepMerger.deep_merge!(source, destination, options) + end + + def self.deep_stringify_keys(hash) + Celsius.deep_stringify_keys!(Celsius.deep_clone(hash)) + end + + # + private + # + + # http://stackoverflow.com/questions/8379596/how-do-i-convert-a-ruby-hash-so-that-all-of-its-keys-are-symbols + def self.deep_stringify_keys!(hash_or_element) + case hash_or_element + when Hash + Hash[ + hash_or_element.map do |key, value| + [ key.respond_to?(:to_s) ? key.to_s : key, deep_stringify_keys(value) ] + end + ] + when Enumerable + hash_or_element.map { |value| deep_stringify_keys(value) } + else + hash_or_element + end + end end