jcrvalidator 0.5.1 → 0.5.2
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/jcr/jcr.rb +48 -31
- data/lib/jcr/parser.rb +8 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c03cef697d981d7516ddc5548984448214d5f02b
|
4
|
+
data.tar.gz: d7d7e596fb44a8e24f88083574269ca13d63fd1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88a219991b6d3cedacce229a592c530740d7e294898cea4d23ff021c25f4d0c512e87a2335a24b1f2b51b7a1ec5df979449dedced2469be6ade2140a447bd959
|
7
|
+
data.tar.gz: 8bcfc4268548f89d2a3d84cd261c4bf1d1264cb897e4f3096b5a417dfc2067b6182c32d36b1653aaeef16ee7bbdee7f9def6c76cdbb0448a0ba4f6a0cb98b1ff
|
data/lib/jcr/jcr.rb
CHANGED
@@ -94,6 +94,7 @@ module JCR
|
|
94
94
|
tree = JCR.parse( ruleset )
|
95
95
|
mapping = JCR.map_rule_names( tree, override, ruleset_alias )
|
96
96
|
JCR.check_rule_target_names( tree, mapping )
|
97
|
+
JCR.check_groups( tree, mapping )
|
97
98
|
roots = JCR.find_roots( tree )
|
98
99
|
ctx = Context.new
|
99
100
|
ctx.tree = tree
|
@@ -120,6 +121,7 @@ module JCR
|
|
120
121
|
|
121
122
|
retval = nil
|
122
123
|
root_rules.each do |r|
|
124
|
+
raise "Root rules cannot be member rules" if r[:member_rule]
|
123
125
|
retval = JCR.evaluate_rule( r, r, data, EvalConditions.new( ctx.mapping, ctx.callbacks ) )
|
124
126
|
break if retval.success
|
125
127
|
end
|
@@ -127,7 +129,9 @@ module JCR
|
|
127
129
|
return retval
|
128
130
|
end
|
129
131
|
|
130
|
-
def self.main
|
132
|
+
def self.main my_argv=nil
|
133
|
+
|
134
|
+
my_argv = ARGV unless my_argv
|
131
135
|
|
132
136
|
options = {}
|
133
137
|
|
@@ -136,6 +140,7 @@ module JCR
|
|
136
140
|
opt.separator ""
|
137
141
|
opt.separator "Evaluates JSON against JSON Content Rules (JCR)."
|
138
142
|
opt.separator ""
|
143
|
+
opt.separator "If -J is not specified, JSON_FILES is used."
|
139
144
|
opt.separator "If JSON_FILES is not specified, standard input (STDIN) is used."
|
140
145
|
opt.separator ""
|
141
146
|
opt.separator "Use -v to see results, otherwise check the exit code."
|
@@ -158,7 +163,7 @@ module JCR
|
|
158
163
|
options[:ruleset] = ruleset
|
159
164
|
end
|
160
165
|
|
161
|
-
opt.on("-
|
166
|
+
opt.on("-S STRING","name of root rule. All roots will be tried if none is specified") do |root_name|
|
162
167
|
if options[:root_name]
|
163
168
|
puts "A root has already been specified. Use -h for help.", ""
|
164
169
|
return 2
|
@@ -180,6 +185,14 @@ module JCR
|
|
180
185
|
options[:overrides] << rule
|
181
186
|
end
|
182
187
|
|
188
|
+
opt.on("-J STRING","string containing JSON to evaluate. Should probably be quoted") do |json|
|
189
|
+
if options[:json]
|
190
|
+
puts "JSON has already been specified. Use -h for help.", ""
|
191
|
+
return 2
|
192
|
+
end
|
193
|
+
options[:json] = json
|
194
|
+
end
|
195
|
+
|
183
196
|
opt.on("-v","verbose") do |verbose|
|
184
197
|
options[:verbose] = true
|
185
198
|
end
|
@@ -189,7 +202,7 @@ module JCR
|
|
189
202
|
end
|
190
203
|
end
|
191
204
|
|
192
|
-
opt_parser.parse!
|
205
|
+
opt_parser.parse! my_argv
|
193
206
|
|
194
207
|
if options[:help]
|
195
208
|
puts "HELP","----",""
|
@@ -208,43 +221,47 @@ module JCR
|
|
208
221
|
end
|
209
222
|
end
|
210
223
|
|
211
|
-
if
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
end
|
225
|
-
ec = 1
|
224
|
+
if options[:json]
|
225
|
+
data = JSON.parse( options[:json] )
|
226
|
+
ec = cli_eval( ctx, data, options[:root_name], options[:verbose] )
|
227
|
+
return ec
|
228
|
+
elsif $stdin.tty?
|
229
|
+
ec = 0
|
230
|
+
if my_argv.empty?
|
231
|
+
ec = 2
|
232
|
+
else
|
233
|
+
my_argv.each do |fn|
|
234
|
+
data = JSON.parse( File.open( fn ).read )
|
235
|
+
tec = cli_eval( ctx, data, options[:root_name], options[:verbose] )
|
236
|
+
ec = tec if tec != 0 #record error but don't let non-error overwrite error
|
226
237
|
end
|
227
238
|
end
|
228
239
|
return ec
|
229
240
|
else
|
230
241
|
data = JSON.parse( ARGF.read )
|
231
|
-
|
232
|
-
|
233
|
-
if options[:verbose]
|
234
|
-
puts "Success!"
|
235
|
-
end
|
236
|
-
return 0
|
237
|
-
else
|
238
|
-
if options[:verbose]
|
239
|
-
puts "Failure: #{e.reason}"
|
240
|
-
end
|
241
|
-
return 1
|
242
|
-
end
|
243
|
-
|
242
|
+
ec = cli_eval( ctx, data, options[:root_name], options[:verbose] )
|
243
|
+
return ec
|
244
244
|
end
|
245
245
|
|
246
246
|
end
|
247
247
|
|
248
248
|
end
|
249
249
|
|
250
|
+
def self.cli_eval ctx, data, root_name, verbose
|
251
|
+
ec = 2
|
252
|
+
e = ctx.evaluate( data, root_name )
|
253
|
+
if e.success
|
254
|
+
if verbose
|
255
|
+
puts "Success!"
|
256
|
+
end
|
257
|
+
ec = 0
|
258
|
+
else
|
259
|
+
if verbose
|
260
|
+
puts "Failure: #{e.reason}"
|
261
|
+
end
|
262
|
+
ec = 1
|
263
|
+
end
|
264
|
+
return ec
|
265
|
+
end
|
266
|
+
|
250
267
|
end
|
data/lib/jcr/parser.rb
CHANGED
@@ -43,15 +43,15 @@ module JCR
|
|
43
43
|
#!
|
44
44
|
|
45
45
|
rule(:directive) { ( str('#') >> spaces? >> directive_def >> match('[\r\n]') ).as(:directive) }
|
46
|
-
#! directive = "#" spaces? directive_def eol
|
46
|
+
#! directive = "#" spaces? directive_def *WSP eol
|
47
47
|
rule(:directive_def) { jcr_version_d | ruleset_id_d | import_d | tbd_directive_d }
|
48
48
|
#! directive_def = jcr_version_d / ruleset_id_d / import_d /
|
49
49
|
#! tbd_directive_d
|
50
|
-
rule(:jcr_version_d) { (str('jcr-version') >> spaces >>
|
50
|
+
rule(:jcr_version_d) { (str('jcr-version') >> spaces >> p_integer.as(:major_version) >> str('.') >> p_integer.as(:minor_version)).as(:jcr_version_d) }
|
51
51
|
#! jcr_version_d = jcr-version-kw spaces major_version "." minor_version
|
52
52
|
#> jcr-version-kw = "jcr-version"
|
53
|
-
#! major_version =
|
54
|
-
#! minor_version =
|
53
|
+
#! major_version = p_integer
|
54
|
+
#! minor_version = p_integer
|
55
55
|
rule(:ruleset_id_d) { (str('ruleset-id') >> spaces >> ruleset_id.as(:ruleset_id)).as(:ruleset_id_d) }
|
56
56
|
#! ruleset_id_d = ruleset-id-kw spaces ruleset_id
|
57
57
|
#> ruleset-id-kw = "ruleset-id"
|
@@ -68,13 +68,13 @@ module JCR
|
|
68
68
|
rule(:tbd_directive_d) { name.as(:directive_name) >> ( spaces >> match('[^\r\n]').repeat.as(:directive_parameters) ).maybe }
|
69
69
|
#! tbd_directive_d = directive_name [ spaces directive_parameters ]
|
70
70
|
#! directive_name = name
|
71
|
-
#! directive_parameters = not_eol
|
71
|
+
#! directive_parameters = *not_eol
|
72
72
|
#! not_eol = HTAB / %x20-10FFFF
|
73
73
|
#! eol = CR / LF
|
74
74
|
#!
|
75
75
|
|
76
|
-
rule(:root_rule) { value_rule |
|
77
|
-
#! root_rule = value_rule /
|
76
|
+
rule(:root_rule) { value_rule | group_rule } # N.B. Not target_rule_name
|
77
|
+
#! root_rule = value_rule / group_rule
|
78
78
|
#!
|
79
79
|
|
80
80
|
rule(:rule) { ( rule_name >> spcCmnt? >> rule_def ).as(:rule) }
|
@@ -355,7 +355,7 @@ module JCR
|
|
355
355
|
#!
|
356
356
|
|
357
357
|
rule(:uri_template) { ( match('[a-zA-Z{}]').repeat(1) >> str(':') >> match('[\S]').repeat(1) ).as(:uri_template) }
|
358
|
-
#! uri_template = 1*ALPHA ":" not-space
|
358
|
+
#! uri_template = 1*ALPHA ":" 1*not-space
|
359
359
|
|
360
360
|
end
|
361
361
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jcrvalidator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Newton
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-02-04 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A JSON Content Rules (JCR) Validator library and command line utility.
|
15
15
|
email: andy@arin.net
|