summaryrefslogtreecommitdiff
path: root/Rakefile
blob: c745f9922a28072e6d92230e865093efccd0d515 (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
29
30
31
32
33
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