require 'json' require 'yaml' # Our custom YAML tags must retain their magic. class TaggedMap < Hash yaml_tag '!code' def init_with(psych_coder) self.replace({:__tag__ => 'code'}.merge(psych_coder.map)) end end YAML::add_tag('code', TaggedMap) desc 'Build all alternate versions of the specs.' multitask :build => [ 'build:json' ] namespace :build do note = 'Do not edit this file; changes belong in the appropriate YAML file.' desc 'Build JSON versions of the specs.' task :json do rm(Dir['specs/*.json'], :verbose => false) Dir.glob('specs/*.yml').each do |filename| json_file = filename.gsub('.yml', '.json') File.open(json_file, 'w') do |file| warning = {:__ATTN__ => note} doc = YAML.load_file(filename) file << JSON.pretty_generate(warning.merge(doc)) << "\n" end end end end