obf 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/obf/validator.rb +36 -20
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5d07ecf16d2203be0d9413839d5d40fef459d1b
|
4
|
+
data.tar.gz: 8197d0663f79ae864f1be1219a7738242ad98296
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 005aa69b9b244383b670bced8b6c43aaa9085f3e7eed91aa4640c567d9eea58520ed5da171915f497d66d8c374ec5e5b2100da6d248698c555969b5996298c17
|
7
|
+
data.tar.gz: a830f23b3501dda0b301d643086913049e55b1a759e4acf9921cf3f858e5fcdbf218ff6b39d1e847e239978399a5aa27df656efdb3194ff42795e3cbb20c54f5
|
data/lib/obf/validator.rb
CHANGED
@@ -10,7 +10,7 @@ module OBF
|
|
10
10
|
begin
|
11
11
|
block.call
|
12
12
|
rescue ValidationError => e
|
13
|
-
@
|
13
|
+
@errors += 1
|
14
14
|
@checks[-1]['valid'] = false
|
15
15
|
@checks[-1]['error'] = e.message
|
16
16
|
@blocked = true if e.blocker
|
@@ -22,14 +22,28 @@ module OBF
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def warn(message)
|
25
|
-
@
|
25
|
+
@warnings += 1
|
26
26
|
@checks[-1]['warnings'] ||= []
|
27
27
|
@checks[-1]['warnings'] << message
|
28
28
|
end
|
29
29
|
|
30
|
+
def errors
|
31
|
+
@errors || 0
|
32
|
+
end
|
33
|
+
|
34
|
+
def warnings
|
35
|
+
@warnings || 0
|
36
|
+
end
|
37
|
+
|
30
38
|
def self.validate_obf(path)
|
31
39
|
v = self.new
|
32
|
-
v.validate_obf(path)
|
40
|
+
results = v.validate_obf(path)
|
41
|
+
{
|
42
|
+
:valid => v.errors == 0,
|
43
|
+
:errors => v.errors,
|
44
|
+
:warnings => v.warnings,
|
45
|
+
:results => results
|
46
|
+
}
|
33
47
|
end
|
34
48
|
|
35
49
|
def self.validate_obz(path)
|
@@ -38,12 +52,14 @@ module OBF
|
|
38
52
|
def validate_obf(path, opts={})
|
39
53
|
@blocked = nil
|
40
54
|
@errored = false
|
55
|
+
@warnings = 0
|
56
|
+
@errors = 0
|
41
57
|
@checks = []
|
42
58
|
|
43
59
|
# TODO enforce extra attributes being defined with ext_
|
44
60
|
|
45
61
|
json = nil
|
46
|
-
add_check('valid_json', "
|
62
|
+
add_check('valid_json', "JSON File") do
|
47
63
|
begin
|
48
64
|
json = JSON.parse(File.read(path))
|
49
65
|
rescue => e
|
@@ -52,7 +68,7 @@ module OBF
|
|
52
68
|
end
|
53
69
|
|
54
70
|
ext = nil
|
55
|
-
add_check('to_external', "
|
71
|
+
add_check('to_external', "OBF Structure") do
|
56
72
|
begin
|
57
73
|
ext = External.from_obf(path, {})
|
58
74
|
rescue External::StructureError => e
|
@@ -60,7 +76,7 @@ module OBF
|
|
60
76
|
end
|
61
77
|
end
|
62
78
|
|
63
|
-
add_check('format_version', "
|
79
|
+
add_check('format_version', "format version") do
|
64
80
|
if !ext['format']
|
65
81
|
err "format attribute is required, set to #{FORMAT}"
|
66
82
|
end
|
@@ -72,20 +88,20 @@ module OBF
|
|
72
88
|
end
|
73
89
|
end
|
74
90
|
|
75
|
-
add_check('id', "
|
91
|
+
add_check('id', "board ID") do
|
76
92
|
if !ext['id']
|
77
93
|
err "id attribute is required"
|
78
94
|
end
|
79
95
|
end
|
80
96
|
|
81
|
-
add_check('locale', "
|
97
|
+
add_check('locale', "locale") do
|
82
98
|
if !ext['locale']
|
83
99
|
err "locale attribute is required, please set to \"en\" for English"
|
84
100
|
end
|
85
101
|
end
|
86
102
|
|
87
|
-
add_check('extras', "
|
88
|
-
attrs = ['format', 'id', 'locale', 'url', 'data_url', 'name', 'description_html', 'buttons', 'images', 'sounds', 'grid', 'license']
|
103
|
+
add_check('extras', "extra attributes") do
|
104
|
+
attrs = ['format', 'id', 'locale', 'url', 'data_url', 'name', 'description_html', 'buttons', 'buttons_hash', 'images', 'images_hash', 'sounds', 'sounds_hash', 'grid', 'license']
|
89
105
|
ext.keys.each do |key|
|
90
106
|
if !attrs.include?(key) && !key.match(/^ext_/)
|
91
107
|
warn "#{key} attribute is not defined in the spec, should be prefixed with ext_yourapp_"
|
@@ -93,7 +109,7 @@ module OBF
|
|
93
109
|
end
|
94
110
|
end
|
95
111
|
|
96
|
-
add_check('description', "
|
112
|
+
add_check('description', "descriptive attributes") do
|
97
113
|
if !ext['name']
|
98
114
|
warn "name attribute is strongly recommended"
|
99
115
|
end
|
@@ -102,7 +118,7 @@ module OBF
|
|
102
118
|
end
|
103
119
|
end
|
104
120
|
|
105
|
-
add_check('buttons', "
|
121
|
+
add_check('buttons', "buttons attribute") do
|
106
122
|
if !ext['buttons']
|
107
123
|
err "buttons attribute is required"
|
108
124
|
elsif !ext['buttons'].is_a?(Array)
|
@@ -110,7 +126,7 @@ module OBF
|
|
110
126
|
end
|
111
127
|
end
|
112
128
|
|
113
|
-
add_check('grid', "
|
129
|
+
add_check('grid', "grid attribute") do
|
114
130
|
if !ext['grid']
|
115
131
|
err "grid attribute is required"
|
116
132
|
elsif !ext['grid'].is_a?(Hash)
|
@@ -144,7 +160,7 @@ module OBF
|
|
144
160
|
end
|
145
161
|
end
|
146
162
|
|
147
|
-
add_check('grid_ids', "
|
163
|
+
add_check('grid_ids', "button IDs in grid.order attribute") do
|
148
164
|
button_ids = []
|
149
165
|
if ext['buttons'] && ext['buttons'].is_a?(Array)
|
150
166
|
ext['buttons'].each{|b| button_ids << b['id'] if b.is_a?(Hash) && b['id'] }
|
@@ -165,7 +181,7 @@ module OBF
|
|
165
181
|
end
|
166
182
|
end
|
167
183
|
warn("board has no buttons defined in the grid") if used_button_ids.length == 0
|
168
|
-
warn("not all defined buttons were included in the grid order") if (button_ids
|
184
|
+
warn("not all defined buttons were included in the grid order (#{(button_ids - used_button_ids).join(',')})") if (button_ids - used_button_ids).length > 0
|
169
185
|
end
|
170
186
|
|
171
187
|
unless opts['obz']
|
@@ -173,7 +189,7 @@ module OBF
|
|
173
189
|
if ext['buttons'] && ext['buttons'].is_a?(Array)
|
174
190
|
ext['buttons'].each{|b| button_image_ids << b['image_id'] if b.is_a?(Hash) && b['image_id'] }
|
175
191
|
end
|
176
|
-
add_check('images', "
|
192
|
+
add_check('images', "images attribute") do
|
177
193
|
|
178
194
|
if !ext['images']
|
179
195
|
err "images attribute is required"
|
@@ -184,7 +200,7 @@ module OBF
|
|
184
200
|
|
185
201
|
if ext['images'] && ext['images'].is_a?(Array)
|
186
202
|
ext['images'].each_with_index do |image, idx|
|
187
|
-
add_check("image[#{idx}]", "
|
203
|
+
add_check("image[#{idx}]", "image at images[#{idx}]") do
|
188
204
|
if !image.is_a?(Hash)
|
189
205
|
err "image must be a hash"
|
190
206
|
elsif !image['id']
|
@@ -213,7 +229,7 @@ module OBF
|
|
213
229
|
end
|
214
230
|
end
|
215
231
|
|
216
|
-
add_check('sounds', "
|
232
|
+
add_check('sounds', "sounds attribute") do
|
217
233
|
|
218
234
|
if !ext['sounds']
|
219
235
|
err "sounds attribute is required"
|
@@ -224,7 +240,7 @@ module OBF
|
|
224
240
|
|
225
241
|
if ext['sounds'] && ext['sounds'].is_a?(Array)
|
226
242
|
ext['sounds'].each_with_index do |sound, idx|
|
227
|
-
add_check("sounds[#{idx}]", "
|
243
|
+
add_check("sounds[#{idx}]", "sound at sounds[#{idx}]") do
|
228
244
|
if !sound.is_a?(Hash)
|
229
245
|
err "sound must be a hash"
|
230
246
|
elsif !sound['id']
|
@@ -252,7 +268,7 @@ module OBF
|
|
252
268
|
|
253
269
|
if ext['buttons'] && ext['buttons'].is_a?(Array)
|
254
270
|
ext['buttons'].each_with_index do |button, idx|
|
255
|
-
add_check("buttons[#{idx}]", "
|
271
|
+
add_check("buttons[#{idx}]", "button at buttons[#{idx}]") do
|
256
272
|
if !button.is_a?(Hash)
|
257
273
|
err "button must be a hash"
|
258
274
|
elsif !button['id']
|