-
Notifications
You must be signed in to change notification settings - Fork 24
/
Rakefile
77 lines (61 loc) · 1.81 KB
/
Rakefile
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
require 'rubygems'
require 'json'
class Armature
METADATA_FILE = "metadata.json"
ATTRIBUTES = [ "arm", "title", "champion", "organization", "effort", "revision", "requires-arms", "project", "issues", "implementation", "discussion" ]
REQUIRED_ATTRS = [ "arm", "title", "champion", "revision", "project" ]
ARRAYS = [ "organization", "requires-arms", "issues" ]
attr_reader :directory
def [](name)
@attributes[name]
end
def []=(name, value)
@attributes[name] = value
end
def initialize(directory)
@attributes = {}
@directory = directory
end
def load
data = parse()
data.each do |key, value|
raise "Invalid Armature attribute '#{key}'" unless ATTRIBUTES.include?(key)
# Make sure all of our list attributes are in the form of an array.
if ARRAYS.include?(key)
value = Array(value)
end
self[key] = value
end
end
def metadata_file
File.join(directory, Armature::METADATA_FILE)
end
def parse
raise "No #{Armature::METADATA_FILE} for #{directory}" unless File.exist?(metadata_file)
begin
JSON.parse(File.read(metadata_file))
rescue => detail
raise "Could not parse metadata file #{metadata_file} for #{directory}: #{detail}"
end
end
def validate
raise "No title for #{self.inspect}" unless self["title"]
raise "No number for #{self.inspect}" unless self["arm"]
print "Validating #{self['title']} - #{self['arm']}"
REQUIRED_ATTRS.each do |key|
raise "No #{key} attribute specified" unless v = self[key] and v != ""
end
puts ""
end
end
task :validate do
Dir.entries(".").find_all { |d| d =~ /^arm-[\d]+\./ }.each do |d|
begin
arm = Armature.new(d)
arm.load
arm.validate
rescue => detail
puts "Could not parse #{d}: #{detail}"
end
end
end