How to overlay YAML files, preferably in Ruby

How can I overlay YAML files without uploading them to http://yamllint.com ?

For example, if I have

people: 1: :name: John Smith :name: Jane Smith 

How can I warn that the last :name overwrites the first :name ?

I am using Ruby 2.1 and Ubuntu 12.04.

+8
ruby yaml
source share
3 answers

The yamllint command line tool does what you want:

 sudo pip install yamllint 

In particular, it has a key-duplicates rule that detects key-duplicates and keys by rewriting each other:

 $ yamllint test.yml test.yml 1:1 warning missing document start "---" (document-start) 4:5 error duplication of key ":name" in mapping (key-duplicates) 

(It has many other rules that you can enable / disable or configure.)

+2
source share

That's what you need?

 require 'yaml' def check_yaml(filename) unless YAML.dump(YAML.load_file(filename)) == File.read(filename).gsub(/\s*#.*/, '') raise 'problem' end end check_yaml 'somefile.yml' 
+2
source share

How to import 1.yaml and then export to 2.yaml and diff 1.yaml 2.yaml ?
I can not provide the code - no nix utils on this machine, but you have an idea.

0
source share

All Articles