Sha256: 63ebd46fdbbb514a6872f569922442745329ebf8e5653fc33e367ede2ef71e30
Contents?: true
Size: 992 Bytes
Versions: 7
Compression:
Stored size: 992 Bytes
Contents
#!/usr/bin/env ruby require 'pathname' require 'json' require 'yaml' root = Pathname.new(__FILE__).dirname.join('..') document_dirs = [root.join('documents'), root.join('test/documents')] documents = document_dirs.map { |d| Pathname.glob(d.join('**/*')) }.inject([], &:+) json_documents = documents.select { |p| p.file? && !['.yml', '.yaml'].include?(p.extname) } json_documents.each do |file| begin json_contents = JSON.parse(file.read) yaml = YAML.dump(json_contents, line_width: -1) yaml_filepath = Pathname.new(file.to_path.chomp('.json') + '.yml') if yaml_filepath.exist? contents = yaml_filepath.read if contents == yaml puts "#{yaml_filepath.to_path} unchanged" else yaml_filepath.write(yaml) puts "#{yaml_filepath.to_path} changed; updated" end else yaml_filepath.write(yaml) puts "#{yaml_filepath.to_path} created" end rescue JSON::ParserError puts "#{file.to_path}: not json" end end
Version data entries
7 entries across 7 versions & 1 rubygems