-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ruby-abnf-extracter
- Loading branch information
Showing
19 changed files
with
690 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,4 @@ atlassian-ide-plugin.xml | |
com_crashlytics_export_strings.xml | ||
|
||
Gemfile.lock | ||
*.gem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,5 +22,5 @@ rescue LoadError | |
require 'jcr' | ||
end | ||
|
||
JCR.main | ||
exit JCR.main | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Copyright (C) 2016 American Registry for Internet Numbers (ARIN) | ||
# | ||
# Permission to use, copy, modify, and/or distribute this software for any | ||
# purpose with or without fee is hereby granted, provided that the above | ||
# copyright notice and this permission notice appear in all copies. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR | ||
# IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
|
||
# This example demonstrates using the JCR Validator with callbacks | ||
# to perform custom validation | ||
|
||
require 'jcr' | ||
|
||
ruleset = <<RULESET | ||
# ruleset-id rfcXXXX | ||
# jcr-version 0.5 | ||
[ 2 my_integers, 2 my_strings ] | ||
; this will be the rule we custom validate | ||
my_integers :0..4 | ||
my_strings ( :"foo" | :"bar" ) | ||
RULESET | ||
|
||
# Create a JCR context. | ||
ctx = JCR::Context.new( ruleset ) | ||
|
||
# A local variable used in the callback closure | ||
my_eval_count = 0 | ||
|
||
# The callback is created using a Proc object | ||
c = Proc.new do |on| | ||
is_even = false | ||
|
||
# called if the rule evaluates to true | ||
# jcr is the rule | ||
# data is the data being evaluated against the rule | ||
on.rule_eval_true do |jcr,data| | ||
my_eval_count = my_eval_count + 1 | ||
is_even = data.to_i % 2 == 0 | ||
end | ||
|
||
# called if the rule evaluates to false | ||
# jcr is the rule | ||
# data is the data being evaluated against the rule | ||
# e is the evaluation of the rule | ||
on.rule_eval_false do |jcr,data,e| | ||
my_eval_count = my_eval_count + 1 | ||
is_even = data.to_i % 2 == 0 | ||
end | ||
|
||
# return the custom validation | ||
is_even | ||
end | ||
|
||
# register the callback to be called for the "my_integers" rule | ||
ctx.callbacks[ "my_integers" ] = c | ||
|
||
data1 = JSON.parse( '[ 2, 4, "foo", "bar" ]') | ||
e = ctx.evaluate( data1 ) | ||
puts "Ruleset evaluation of JSON = " + e.success.to_s | ||
puts "my_eval_count = " + my_eval_count.to_s | ||
|
||
data2 = JSON.parse( '[ 3, 4, "foo", "bar" ]') | ||
e = ctx.evaluate( data2 ) | ||
puts "Ruleset evaluation of JSON = " + e.success.to_s | ||
puts "my_eval_count = " + my_eval_count.to_s |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
my_integers : 0..2 | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[ | ||
3, 4, | ||
"bar", "foo" | ||
] |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#@IgnoreInspection BashAddShebang | ||
# Copyright (C) 2015 American Registry for Internet Numbers (ARIN) | ||
# | ||
# Permission to use, copy, modify, and/or distribute this software for any | ||
# purpose with or without fee is hereby granted, provided that the above | ||
# copyright notice and this permission notice appear in all copies. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR | ||
# IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
|
||
|
||
# Pass JSON into the JCR validator against a ruleset given on the command line | ||
# This one should succeed | ||
echo | ||
echo "[ 1, 2]" | jcr -v -R "[ *:integer ]" | ||
if [ $? != 0 ]; then | ||
echo "** Unexpected return value" | ||
fi | ||
|
||
# Pass JSON into the JCR validator against a ruleset given on the command line | ||
# This one should fail | ||
echo | ||
echo "[ 1, 2]" | jcr -v -R "[ *:string ]" | ||
if [ $? != 1 ]; then | ||
echo "** Unexpected return value" | ||
else | ||
echo "Failed to validate - this is expected" | ||
fi | ||
|
||
# Pass JSON into the JCR validator from a file with a ruleset specified in a file | ||
# This one should succeed | ||
echo | ||
jcr -v -r example1.jcr example1a.json | ||
if [ $? != 0 ]; then | ||
echo "** Unexpected return value" | ||
fi | ||
|
||
# Pass JSON into the JCR validator from a file with a ruleset specified in a file | ||
# This one should succeed | ||
echo | ||
jcr -v -r example1.jcr example1b.json | ||
if [ $? != 0 ]; then | ||
echo "** Unexpected return value" | ||
fi | ||
|
||
# Pass multiple JSON files into the JCR validator using a ruleset specified in a file | ||
echo | ||
jcr -v -r example1.jcr example1*.json | ||
if [ $? != 0 ]; then | ||
echo "** Unexpected return value" | ||
fi | ||
|
||
# Override a rule from the command line | ||
# Should succeed | ||
echo | ||
jcr -v -r example1.jcr -O "my_integers :0..2" example1a.json | ||
if [ $? != 0 ]; then | ||
echo "** Unexpected return value" | ||
fi | ||
|
||
# Override a rule from the command line | ||
# Should fail | ||
echo | ||
jcr -v -r example1.jcr -O "my_integers :0..2" example1b.json | ||
if [ $? != 1 ]; then | ||
echo "** Unexpected return value" | ||
else | ||
echo "Failed to validate - this is expected" | ||
fi | ||
|
||
# Override a rule from a file | ||
# Should succeed | ||
echo | ||
jcr -v -r example1.jcr -o example1_override.jcr example1a.json | ||
if [ $? != 0 ]; then | ||
echo "** Unexpected return value" | ||
fi | ||
|
||
# Override a rule from a file | ||
# Should fail | ||
echo | ||
jcr -v -r example1.jcr -o example1_override.jcr example1b.json | ||
if [ $? != 1 ]; then | ||
echo "** Unexpected return value" | ||
else | ||
echo "Failed to validate - this is expected" | ||
fi | ||
|
Oops, something went wrong.