summaryrefslogtreecommitdiff
path: root/Rakefile
blob: 6c6008fb8fcfaca265b28633aed9400f788aa05e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require 'json'
require 'yaml'

# Our custom YAML tags must retain their magic.
%w[ code ].each do |tag|
  YAML::add_builtin_type(tag) { |_,val| val.merge(:__tag__ => tag) }
end

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