Sha256: 438050e86dcbdb3c0226f4b92ad1dc09a098f9d5b9eb6801b7cec57ce81f1b94
Contents?: true
Size: 1.2 KB
Versions: 15
Compression:
Stored size: 1.2 KB
Contents
module Ecoportal module API module Common module HashDiff ID_KEYS = %w[id] class << self def diff(a, b, ignore: []) case a when Hash {}.tap do |diffed| a.each do |key, a_value| b_value = b && b[key] no_changes = (a_value == b_value) || ignore.include?(key) next if !ID_KEYS.include?(key) && no_changes diffed[key] = diff(a_value, b_value, ignore: ignore) diffed.delete(key) if diffed[key] == {} end # All keys are IDs, so it's actually blank if (diffed.keys - ID_KEYS).empty? return {} end end when Array return a unless b.is_a?(Array) && a.length == b.length a.map.with_index do |a_value, idx| b_value = b[idx] diff(a_value, b_value, ignore: ignore) end.reject do |el| el == {} end else a end end end end end end end
Version data entries
15 entries across 15 versions & 1 rubygems