Skip to content

Instantly share code, notes, and snippets.

@joost
Created November 9, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joost/463c323d6e05ac4a4ead to your computer and use it in GitHub Desktop.
Save joost/463c323d6e05ac4a4ead to your computer and use it in GitHub Desktop.
Compare two YAML files
def compare_yaml_hash(cf1, cf2, context = [])
cf1.each do |key, value|
unless cf2.key?(key)
puts "Missing key : #{key} in path #{context.join(".")}"
next
end
value2 = cf2[key]
if (value.class != value2.class)
puts "Key value type mismatch : #{key} in path #{context.join(".")}"
next
end
if value.is_a?(Hash)
compare_yaml_hash(value, value2, (context + [key]))
next
end
if (value != value2)
puts "Key value mismatch : #{key} in path #{context.join(".")}"
end
end
nil
end
compare_yaml_hash(YAML.load_file('file1.yml'), YAML.load_file('file2.yml'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment