require_relative "../i18n" module Skala::I18n::DeepMerger def self.deep_merge!(destination, source, options = {}) if destination.kind_of?(Array) if source.kind_of?(Array) # array into array source.each do |element| self.deep_merge!(destination, element, options) end elsif source.kind_of?(Hash) # hash into array destination.push(source) else # literal into array destination.push(source) end elsif destination.kind_of?(Hash) if source.kind_of?(Array) # array into hash raise ArgumentError, "Cannot merge array into hash!" elsif source.kind_of?(Hash) # hash into hash destination.merge!(source) do |key, destination_value, source_value| self.deep_merge!(destination_value, source_value, options) destination_value end else # literal into hash raise ArgumentError, "Cannot merge literal into hash!" end else if source.kind_of?(Array) # array into literal raise ArgumentError, "Cannot merge array into literal!" elsif source.kind_of?(Hash) # hash into literal raise ArgumentError, "Cannot merge hash into literal!" else # literal into literal destination = source # in fact a useless assignment to fit into the overall semantic end end end end