class RuboCop::Schema::Diff
Public Class Methods
apply(old, diff)
click to toggle source
# File lib/rubocop/schema/diff.rb, line 17 def apply(old, diff) instance.apply old, diff end
diff(old, new)
click to toggle source
# File lib/rubocop/schema/diff.rb, line 13 def diff(old, new) instance.diff old, new end
instance()
click to toggle source
# File lib/rubocop/schema/diff.rb, line 9 def instance @instance ||= new end
Public Instance Methods
apply(old, diff)
click to toggle source
# File lib/rubocop/schema/diff.rb, line 28 def apply(old, diff) return apply_hash(old, diff) if old.is_a?(Hash) && diff.is_a?(Hash) diff end
diff(old, new)
click to toggle source
# File lib/rubocop/schema/diff.rb, line 22 def diff(old, new) return diff_hashes old, new if old.is_a?(Hash) && new.is_a?(Hash) new end
Private Instance Methods
apply_hash(old, diff)
click to toggle source
# File lib/rubocop/schema/diff.rb, line 48 def apply_hash(old, diff) deep_dup(old).tap do |result| diff.each do |k, v| apply_hash_pair result, k, v end end end
apply_hash_pair(hash, key, value)
click to toggle source
# File lib/rubocop/schema/diff.rb, line 56 def apply_hash_pair(hash, key, value) if value.nil? hash.delete key elsif hash.key? key hash[key] = apply(hash[key], value) else hash[key] = value end end
diff_hashes(old, new)
click to toggle source
# File lib/rubocop/schema/diff.rb, line 36 def diff_hashes(old, new) (old.keys - new.keys).map { |k| [k, nil] }.to_h.tap do |result| new.each do |k, v| if old.key? k result[k] = diff(old[k], v) unless old[k] == v else result[k] = v end end end end