kwalify 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +232 -0
- data/MIT-LICENSE +20 -0
- data/README.txt +16 -19
- data/bin/kwalify +3 -3
- data/contrib/inline-require +6 -4
- data/contrib/kwalify +3719 -2427
- data/doc-api/classes/CommandOptionError.html +17 -17
- data/doc-api/classes/CommandOptionParser.html +63 -63
- data/doc-api/classes/Kwalify.html +29 -7
- data/doc-api/classes/Kwalify/AssertionError.html +9 -9
- data/doc-api/classes/Kwalify/BaseError.html +72 -71
- data/doc-api/classes/Kwalify/BaseParser.html +461 -0
- data/doc-api/classes/Kwalify/CommandOptionError.html +11 -11
- data/doc-api/classes/Kwalify/ErrorHelper.html +51 -46
- data/doc-api/classes/Kwalify/HashInterface.html +13 -135
- data/doc-api/classes/Kwalify/Json.html +105 -0
- data/doc-api/classes/Kwalify/Main.html +129 -126
- data/doc-api/classes/Kwalify/MetaValidator.html +248 -232
- data/doc-api/classes/Kwalify/Parser.html +12 -12
- data/doc-api/classes/Kwalify/PlainYamlParser.html +166 -163
- data/doc-api/classes/Kwalify/PlainYamlParser/Alias.html +11 -11
- data/doc-api/classes/Kwalify/Rule.html +152 -130
- data/doc-api/classes/Kwalify/SchemaError.html +10 -10
- data/doc-api/classes/Kwalify/SyntaxError.html +185 -0
- data/doc-api/classes/Kwalify/Types.html +26 -25
- data/doc-api/classes/Kwalify/Util.html +389 -0
- data/doc-api/classes/Kwalify/Util/HashLike.html +246 -0
- data/doc-api/classes/Kwalify/Util/OrderedHash.html +330 -0
- data/doc-api/classes/Kwalify/ValidationError.html +10 -10
- data/doc-api/classes/Kwalify/Validator.html +153 -86
- data/doc-api/classes/Kwalify/Yaml.html +181 -0
- data/doc-api/classes/Kwalify/Yaml/Parser.html +1538 -0
- data/doc-api/classes/Kwalify/YamlParser.html +190 -183
- data/doc-api/classes/Kwalify/YamlSyntaxError.html +8 -57
- data/doc-api/created.rid +1 -1
- data/doc-api/files/__/README_txt.html +17 -22
- data/doc-api/files/kwalify/errors_rb.html +2 -2
- data/doc-api/files/kwalify/main_rb.html +4 -3
- data/doc-api/files/kwalify/messages_rb.html +2 -2
- data/doc-api/files/kwalify/meta-validator_rb.html +3 -3
- data/doc-api/files/kwalify/{util/yaml-helper_rb.html → parser/base_rb.html} +8 -6
- data/doc-api/files/kwalify/parser/yaml_rb.html +117 -0
- data/doc-api/files/kwalify/rule_rb.html +2 -2
- data/doc-api/files/kwalify/types_rb.html +2 -2
- data/doc-api/files/kwalify/util/assert-text-equal_rb.html +2 -2
- data/doc-api/files/kwalify/util/hash-interface_rb.html +9 -2
- data/doc-api/files/kwalify/util/hashlike_rb.html +107 -0
- data/doc-api/files/kwalify/util/option-parser_rb.html +2 -2
- data/doc-api/files/kwalify/util/ordered-hash_rb.html +107 -0
- data/doc-api/files/kwalify/util/testcase-helper_rb.html +2 -2
- data/doc-api/files/kwalify/util_rb.html +107 -0
- data/doc-api/files/kwalify/validator_rb.html +2 -2
- data/doc-api/files/kwalify/yaml-parser_rb.html +2 -2
- data/doc-api/files/kwalify_rb.html +3 -2
- data/doc-api/fr_class_index.html +8 -1
- data/doc-api/fr_file_index.html +5 -1
- data/doc-api/fr_method_index.html +128 -69
- data/doc/img/fig01.png +0 -0
- data/doc/users-guide.html +882 -717
- data/examples/address-book/address-book.schema.yaml +2 -2
- data/examples/data-binding/BABEL.data.yaml +63 -0
- data/examples/data-binding/BABEL.schema.yaml +31 -0
- data/examples/data-binding/Makefile +8 -0
- data/examples/data-binding/Rakefile +13 -0
- data/examples/data-binding/main.rb +27 -0
- data/examples/invoice/invoice.schema.yaml +3 -3
- data/examples/tapkit/tapkit.schema.yaml +2 -2
- data/lib/kwalify.rb +41 -4
- data/lib/kwalify/errors.rb +118 -96
- data/lib/kwalify/kwalify.schema.yaml +58 -0
- data/lib/kwalify/main.rb +384 -377
- data/lib/kwalify/messages.rb +41 -27
- data/lib/kwalify/meta-validator.rb +251 -331
- data/lib/kwalify/parser/base.rb +127 -0
- data/lib/kwalify/parser/yaml.rb +837 -0
- data/lib/kwalify/rule.rb +545 -487
- data/lib/kwalify/templates/genclass-java.eruby +189 -162
- data/lib/kwalify/templates/genclass-php.eruby +104 -0
- data/lib/kwalify/templates/genclass-ruby.eruby +95 -66
- data/lib/kwalify/types.rb +107 -106
- data/lib/kwalify/util.rb +157 -0
- data/lib/kwalify/util/assert-text-equal.rb +33 -31
- data/lib/kwalify/util/hash-interface.rb +11 -30
- data/lib/kwalify/util/hashlike.rb +51 -0
- data/lib/kwalify/util/option-parser.rb +144 -144
- data/lib/kwalify/util/ordered-hash.rb +57 -0
- data/lib/kwalify/util/testcase-helper.rb +3 -3
- data/lib/kwalify/validator.rb +267 -212
- data/lib/kwalify/yaml-parser.rb +822 -768
- data/setup.rb +861 -607
- data/test/Rookbook.yaml +10 -0
- data/test/{tmp.dir/Context.java → data/users-guide/AddressBook.java.expected} +11 -11
- data/test/data/users-guide/BABEL.data.yaml +24 -0
- data/test/data/users-guide/BABEL.schema.yaml +30 -0
- data/test/data/users-guide/ExampleAddressBook.java +47 -0
- data/test/{tmp.dir/Group.java → data/users-guide/Group.java.expected} +2 -11
- data/test/data/users-guide/Person.java.expected +44 -0
- data/test/data/users-guide/address_book.rb +52 -0
- data/test/data/users-guide/address_book.schema.yaml +28 -0
- data/test/data/users-guide/address_book.yaml +27 -0
- data/test/data/users-guide/answers-schema.yaml +12 -0
- data/test/data/users-guide/answers-validator.rb +52 -0
- data/test/data/users-guide/babel_genclass.result +26 -0
- data/test/data/users-guide/config.schema.yaml +7 -0
- data/test/data/users-guide/config.yaml +4 -0
- data/test/{tmp.dir/silent1.document → data/users-guide/document01a.yaml} +0 -0
- data/test/data/users-guide/document01b.yaml +3 -0
- data/test/data/users-guide/document02a.yaml +4 -0
- data/test/data/users-guide/document02b.yaml +4 -0
- data/test/data/users-guide/document03a.yaml +6 -0
- data/test/data/users-guide/document03b.yaml +6 -0
- data/test/data/users-guide/document04a.yaml +9 -0
- data/test/data/users-guide/document04b.yaml +9 -0
- data/test/data/users-guide/document05a.yaml +11 -0
- data/test/data/users-guide/document05b.yaml +12 -0
- data/test/data/users-guide/document06a.yaml +15 -0
- data/test/data/users-guide/document06b.yaml +16 -0
- data/test/data/users-guide/document07a.yaml +9 -0
- data/test/data/users-guide/document07b.yaml +7 -0
- data/test/data/users-guide/document12a.json +10 -0
- data/test/data/users-guide/document12b.json +6 -0
- data/test/data/users-guide/document13a.yaml +17 -0
- data/test/data/users-guide/document14a.yaml +3 -0
- data/test/data/users-guide/document14b.yaml +3 -0
- data/test/data/users-guide/document15a.yaml +6 -0
- data/test/data/users-guide/document15b.yaml +5 -0
- data/test/data/users-guide/example_address_book.rb +10 -0
- data/test/data/users-guide/example_address_book_java.result +32 -0
- data/test/data/users-guide/example_address_book_ruby.result +31 -0
- data/test/data/users-guide/genclass_java.result +4 -0
- data/test/data/users-guide/howto-validation-with-parsing.rb +28 -0
- data/test/data/users-guide/howto-validation.rb +25 -0
- data/test/data/users-guide/howto3.rb +6 -0
- data/test/data/users-guide/howto3.result +5 -0
- data/test/data/users-guide/howto3.yaml +8 -0
- data/test/data/users-guide/howto5_databinding.result +111 -0
- data/test/data/users-guide/invalid01.result +3 -0
- data/test/data/users-guide/invalid02.result +5 -0
- data/test/data/users-guide/invalid03.result +5 -0
- data/test/data/users-guide/invalid04.result +4 -0
- data/test/data/users-guide/invalid05.result +11 -0
- data/test/data/users-guide/invalid06.result +4 -0
- data/test/data/users-guide/invalid07.result +3 -0
- data/test/data/users-guide/invalid08.result +3 -0
- data/test/data/users-guide/invalid12.json +8 -0
- data/test/data/users-guide/invalid14.result +4 -0
- data/test/data/users-guide/invalid15.result +4 -0
- data/test/data/users-guide/loadbabel.rb +27 -0
- data/test/data/users-guide/loadconfig.rb +15 -0
- data/test/data/users-guide/loadconfig.result +2 -0
- data/test/data/users-guide/models.rb +22 -0
- data/test/data/users-guide/option_ha.result +6 -0
- data/test/data/users-guide/option_ha_genclass_java.result +7 -0
- data/test/{tmp.dir/meta1.schema → data/users-guide/schema01.yaml} +0 -0
- data/test/data/users-guide/schema02.yaml +12 -0
- data/test/data/users-guide/schema03.yaml +9 -0
- data/test/data/users-guide/schema04.yaml +20 -0
- data/test/data/users-guide/schema05.yaml +29 -0
- data/test/data/users-guide/schema06.yaml +11 -0
- data/test/data/users-guide/schema12.json +12 -0
- data/test/data/users-guide/schema13.yaml +13 -0
- data/test/data/users-guide/schema14.yaml +5 -0
- data/test/data/users-guide/schema15.yaml +21 -0
- data/test/data/users-guide/valid01.result +2 -0
- data/test/data/users-guide/valid02.result +2 -0
- data/test/data/users-guide/valid03.result +2 -0
- data/test/data/users-guide/valid04.result +2 -0
- data/test/data/users-guide/valid05.result +2 -0
- data/test/data/users-guide/valid06.result +2 -0
- data/test/data/users-guide/valid07.result +2 -0
- data/test/data/users-guide/valid08.result +2 -0
- data/test/data/users-guide/valid12.result +2 -0
- data/test/data/users-guide/valid13.result +2 -0
- data/test/data/users-guide/valid14.result +2 -0
- data/test/data/users-guide/valid15.result +2 -0
- data/test/data/users-guide/validate08.rb +37 -0
- data/test/test-action.rb +78 -0
- data/test/test-action.yaml +738 -0
- data/test/test-databinding.rb +80 -0
- data/test/test-databinding.yaml +301 -0
- data/test/test-main.rb +129 -150
- data/test/test-main.yaml +126 -321
- data/test/test-metavalidator.rb +47 -47
- data/test/test-metavalidator.yaml +77 -21
- data/test/test-parser-yaml.rb +57 -0
- data/test/test-parser-yaml.yaml +1749 -0
- data/test/test-rule.rb +14 -15
- data/test/test-rule.yaml +6 -3
- data/test/test-users-guide.rb +75 -0
- data/test/test-validator.rb +77 -52
- data/test/test-validator.yaml +168 -6
- data/test/test-yaml-parser.rb +47 -0
- data/test/{test-yamlparser.yaml → test-yaml-parser.yaml} +159 -52
- data/test/test.rb +37 -21
- metadata +136 -37
- data/COPYING +0 -340
- data/ChangeLog +0 -70
- data/doc-api/classes/YamlHelper.html +0 -259
- data/lib/kwalify/util/yaml-helper.rb +0 -82
- data/test/test-yamlparser.rb +0 -58
- data/test/tmp.dir/User.java +0 -43
- data/test/tmp.dir/action1.document +0 -18
- data/test/tmp.dir/action1.schema +0 -32
- data/test/tmp.dir/action2.document +0 -18
- data/test/tmp.dir/action2.schema +0 -32
- data/test/tmp.dir/emacs.document +0 -6
- data/test/tmp.dir/emacs.schema +0 -6
- data/test/tmp.dir/meta1.document +0 -0
- data/test/tmp.dir/meta2.document +0 -0
- data/test/tmp.dir/meta2.schema +0 -3
- data/test/tmp.dir/silent1.schema +0 -3
- data/test/tmp.dir/silent2.document +0 -7
- data/test/tmp.dir/silent2.schema +0 -3
- data/test/tmp.dir/stream.invalid +0 -8
- data/test/tmp.dir/stream.schema +0 -3
- data/test/tmp.dir/stream.valid +0 -8
- data/test/tmp.dir/untabify.document +0 -5
- data/test/tmp.dir/untabify.schema +0 -10
- data/todo.txt +0 -34
@@ -1,8 +1,8 @@
|
|
1
1
|
##
|
2
2
|
## Kwalify schema example for address book
|
3
3
|
##
|
4
|
-
## $Release: 0.
|
5
|
-
## copyright(c) 2005 kuwata-lab all rights reserved.
|
4
|
+
## $Release: 0.7.0 $
|
5
|
+
## copyright(c) 2005-2008 kuwata-lab all rights reserved.
|
6
6
|
##
|
7
7
|
##
|
8
8
|
## NOTE: 'type: str' is omitted in this example because 'str' is default type.
|
@@ -0,0 +1,63 @@
|
|
1
|
+
teams:
|
2
|
+
- &thechildren
|
3
|
+
name: The Children
|
4
|
+
desc: Level 7 ESPers
|
5
|
+
chief: *minamoto # preceding alias
|
6
|
+
members: [*kaoru, *aoi, *shiho] # preceding alias
|
7
|
+
- &thewildcat
|
8
|
+
name: The WildCat
|
9
|
+
desc: Level 6 Esper
|
10
|
+
chief: *tanizaki # preceding alias
|
11
|
+
members: [*naomi] # preceding alias
|
12
|
+
- &thehounds
|
13
|
+
name: The Hounds
|
14
|
+
desc: Hatsune & Akira
|
15
|
+
chief: *kojika # preceding alias
|
16
|
+
members: [*hatsune, *akira] # preceding alias
|
17
|
+
|
18
|
+
members:
|
19
|
+
- &minamoto
|
20
|
+
name: Kohichi Minamoto
|
21
|
+
desc: Scientist
|
22
|
+
team: *thechildren
|
23
|
+
kind: normal
|
24
|
+
- &kaoru
|
25
|
+
name: Kaoru Akashi
|
26
|
+
desc: Psychokino
|
27
|
+
team: *thechildren
|
28
|
+
kind: esper
|
29
|
+
- &aoi
|
30
|
+
name: Aoi Nogami
|
31
|
+
desc: Teleporter
|
32
|
+
team: *thechildren
|
33
|
+
kind: esper
|
34
|
+
- &shiho
|
35
|
+
name: Shiho Sannomiya
|
36
|
+
desc: Psycometrer
|
37
|
+
team: *thechildren
|
38
|
+
kind: esper
|
39
|
+
- &tanizaki
|
40
|
+
name: Ichiro Tanizaki
|
41
|
+
desc: Hentai Oyaji
|
42
|
+
team: *thewildcat
|
43
|
+
kind: normal
|
44
|
+
- &naomi
|
45
|
+
name: Naomi Umegae
|
46
|
+
desc: Psychokino
|
47
|
+
team: *thewildcat
|
48
|
+
kind: esper
|
49
|
+
- &kojika
|
50
|
+
name: Keiko Kojika
|
51
|
+
desc: Naturalist
|
52
|
+
team: *thehounds
|
53
|
+
kind: normal
|
54
|
+
- &hatsune
|
55
|
+
name: Hatsune Inugami
|
56
|
+
desc: Wolfwoman
|
57
|
+
team: *thehounds
|
58
|
+
kind: esper
|
59
|
+
- &akira
|
60
|
+
name: Akira Yadorigi
|
61
|
+
desc: Animal Controller
|
62
|
+
team: *thehounds
|
63
|
+
kind: esper
|
@@ -0,0 +1,31 @@
|
|
1
|
+
type: map
|
2
|
+
required: yes
|
3
|
+
mapping:
|
4
|
+
"teams":
|
5
|
+
type: seq
|
6
|
+
required: yes
|
7
|
+
sequence:
|
8
|
+
- &team
|
9
|
+
type: map
|
10
|
+
required: yes
|
11
|
+
class: Team
|
12
|
+
mapping:
|
13
|
+
"name": {type: str, required: yes, unique: yes}
|
14
|
+
"desc": {type: str}
|
15
|
+
"chief": *member # preceding alias
|
16
|
+
"members":
|
17
|
+
type: seq
|
18
|
+
sequence: [*member] # preceding alias
|
19
|
+
"members":
|
20
|
+
type: seq
|
21
|
+
required: yes
|
22
|
+
sequence:
|
23
|
+
- &member
|
24
|
+
type: map
|
25
|
+
required: yes
|
26
|
+
class: Member
|
27
|
+
mapping:
|
28
|
+
"name": {type: str, required: yes, unique: yes}
|
29
|
+
"desc": {type: str}
|
30
|
+
"team": *team
|
31
|
+
"kind": {type: str, enum: [normal, esper] }
|
@@ -0,0 +1,13 @@
|
|
1
|
+
task :default => 'main'
|
2
|
+
|
3
|
+
task 'main' => ['models.rb'] do
|
4
|
+
sh "ruby main.rb"
|
5
|
+
end
|
6
|
+
|
7
|
+
file 'models.rb' => ['BABEL.schema.yaml'] do
|
8
|
+
sh "kwalify -a genclass-ruby -f BABEL.schema.yaml -tP --hashlike --module=Babel --initialize=false > models.rb"
|
9
|
+
end
|
10
|
+
|
11
|
+
task 'clean' do
|
12
|
+
rm_f 'models.rb'
|
13
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'kwalify'
|
2
|
+
require 'models'
|
3
|
+
|
4
|
+
## load schema definition
|
5
|
+
schema = Kwalify::Yaml.load_file('BABEL.schema.yaml',
|
6
|
+
:untabify=>true,
|
7
|
+
:preceding_alias=>true)
|
8
|
+
|
9
|
+
## add module name to 'class:'
|
10
|
+
Kwalify::Util.traverse_schema(schema) do |rulehash|
|
11
|
+
if rulehash['class']
|
12
|
+
rulehash['class'] = 'Babel::' + rulehash['class']
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
## create validator
|
17
|
+
validator = Kwalify::Validator.new(schema)
|
18
|
+
|
19
|
+
## parse with data-binding
|
20
|
+
parser = Kwalify::Yaml::Parser.new(validator)
|
21
|
+
parser.preceding_alias = true
|
22
|
+
parser.data_binding = true
|
23
|
+
ydoc = parser.parse_file('BABEL.data.yaml', :untabify=>true)
|
24
|
+
|
25
|
+
## show document
|
26
|
+
require 'pp'
|
27
|
+
pp ydoc
|
@@ -1,9 +1,9 @@
|
|
1
1
|
###
|
2
2
|
### Kwalify schema example for invoice
|
3
3
|
###
|
4
|
-
### $Rev:
|
5
|
-
### $Release: 0.
|
6
|
-
### copyright(c) 2005 kuwata-lab all rights reserved.
|
4
|
+
### $Rev: 83 $
|
5
|
+
### $Release: 0.7.0 $
|
6
|
+
### copyright(c) 2005-2008 kuwata-lab all rights reserved.
|
7
7
|
###
|
8
8
|
|
9
9
|
type: map
|
data/lib/kwalify.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
###
|
2
|
-
### $Rev:
|
3
|
-
### $Release: 0.
|
4
|
-
### copyright(c)
|
2
|
+
### $Rev: 95 $
|
3
|
+
### $Release: 0.7.0 $
|
4
|
+
### copyright(c) 2006 kuwata-lab.com all rights reserved.
|
5
5
|
###
|
6
6
|
|
7
7
|
|
8
8
|
module Kwalify
|
9
9
|
|
10
|
-
|
10
|
+
RELEASE = ("$Release: 0.7.0 $" =~ /[.\d]+/) && $&
|
11
11
|
|
12
12
|
end
|
13
13
|
|
@@ -18,3 +18,40 @@ require 'kwalify/rule'
|
|
18
18
|
require 'kwalify/validator'
|
19
19
|
require 'kwalify/meta-validator'
|
20
20
|
require 'kwalify/yaml-parser'
|
21
|
+
#require 'kwalify/parser/base'
|
22
|
+
#require 'kwalify/parser/yaml'
|
23
|
+
|
24
|
+
|
25
|
+
module Kwalify
|
26
|
+
|
27
|
+
module Util
|
28
|
+
|
29
|
+
autoload :HashLike, 'kwalify/util/hashlike'
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
module Yaml
|
34
|
+
|
35
|
+
autoload :Parser, 'kwalify/parser/yaml'
|
36
|
+
|
37
|
+
def self.load(yaml_str, options={})
|
38
|
+
#require 'kwalify/parser/yaml'
|
39
|
+
parser = Kwalify::Yaml::Parser.new
|
40
|
+
parser.preceding_alias = true if options[:preceding_alias]
|
41
|
+
parser.data_binding = true if options[:data_binding]
|
42
|
+
yaml_str = Kwalify::Util.untabify(yaml_str) if options[:untabify]
|
43
|
+
ydoc = parser.parse(yaml_str, :filename=>options[:filename])
|
44
|
+
return ydoc
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.load_file(filename, options={})
|
48
|
+
options[:filename] = filename
|
49
|
+
return self.load(File.read(filename), options)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
module Json
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
data/lib/kwalify/errors.rb
CHANGED
@@ -1,105 +1,127 @@
|
|
1
1
|
###
|
2
|
-
### $Rev:
|
3
|
-
### $Release: 0.
|
4
|
-
### copyright(c) 2005 kuwata-lab all rights reserved.
|
2
|
+
### $Rev: 93 $
|
3
|
+
### $Release: 0.7.0 $
|
4
|
+
### copyright(c) 2005-2008 kuwata-lab all rights reserved.
|
5
5
|
###
|
6
6
|
|
7
7
|
require 'kwalify/messages'
|
8
8
|
|
9
9
|
module Kwalify
|
10
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
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
11
|
+
class KwalifyError < StandardError
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
class AssertionError < KwalifyError
|
16
|
+
def initialize(msg)
|
17
|
+
super("*** assertion error: " + msg)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
class BaseError < KwalifyError
|
23
|
+
def initialize(message="", path=nil, value=nil, rule=nil, error_symbol=nil)
|
24
|
+
super(message)
|
25
|
+
@path = path
|
26
|
+
@rule = rule
|
27
|
+
@value = value
|
28
|
+
@error_symbol = error_symbol
|
29
|
+
end
|
30
|
+
attr_accessor :error_symbol, :rule, :path, :value
|
31
|
+
attr_accessor :filename, :linenum, :column
|
32
|
+
|
33
|
+
def path
|
34
|
+
return @path == '' ? "/" : @path
|
35
|
+
end
|
36
|
+
|
37
|
+
alias _to_s to_s
|
38
|
+
alias message to_s
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
s = ''
|
42
|
+
s << @filename << ":" if @filename
|
43
|
+
s << "#{@linenum}:#{@column} " if @linenum
|
44
|
+
s << "[#{path()}] " if @path
|
45
|
+
s << _to_s()
|
46
|
+
return s
|
47
|
+
end
|
48
|
+
|
49
|
+
def <=>(ex)
|
50
|
+
#return @linenum <=> ex.linenum
|
51
|
+
v = 0
|
52
|
+
v = @linenum <=> ex.linenum if @linenum && ex.linenum
|
53
|
+
v = @column <=> ex.column if v == 0 && @column && ex.column
|
54
|
+
v = @path <=> ex.path if v == 0
|
55
|
+
return v
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
class SchemaError < BaseError
|
61
|
+
def initialize(message="", path=nil, rule=nil, value=nil, error_symbol=nil)
|
62
|
+
super(message, path, rule, value, error_symbol)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
class ValidationError < BaseError
|
68
|
+
def initialize(message="", path=nil, rule=nil, value=nil, error_symbol=nil)
|
69
|
+
super(message, path, rule, value, error_symbol)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
## syntax error for YAML and JSON
|
75
|
+
class SyntaxError < BaseError #KwalifyError
|
76
|
+
def initialize(msg, linenum=nil, error_symbol=nil)
|
77
|
+
super(linenum ? "line #{linenum}: #{msg}" : msg)
|
78
|
+
@linenum = linenum
|
79
|
+
@error_symbol = error_symbol
|
80
|
+
end
|
81
|
+
#attr_accessor :linenum, :error_symbol
|
82
|
+
def message
|
83
|
+
"file: #{@filename}, line #{@linenum}: #{super}"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
## (obsolete) use Kwalify::SyntaxError instead
|
89
|
+
class YamlSyntaxError < SyntaxError
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
module ErrorHelper
|
94
|
+
|
95
|
+
#module_function
|
96
|
+
|
97
|
+
def assert_error(message="")
|
98
|
+
raise AssertionError.new(message)
|
99
|
+
end
|
100
|
+
|
101
|
+
def validate_error(error_symbol, rule, path, val, args=nil)
|
102
|
+
msg = _build_message(error_symbol, val, args);
|
103
|
+
path = '/'+path.join('/') if path.is_a?(Array)
|
104
|
+
return ValidationError.new(msg, path, val, rule, error_symbol)
|
105
|
+
end
|
106
|
+
module_function :validate_error
|
107
|
+
|
108
|
+
def schema_error(error_symbol, rule, path, val, args=nil)
|
109
|
+
msg = _build_message(error_symbol, val, args);
|
110
|
+
path = '/'+path.join('/') if path.is_a?(Array)
|
111
|
+
return SchemaError.new(msg, path, val, rule, error_symbol)
|
112
|
+
end
|
113
|
+
|
114
|
+
def _build_message(message_key, val, args)
|
115
|
+
msg = Kwalify.msg(message_key)
|
116
|
+
assert_error("message_key=#{message_key.inspect}") unless msg
|
117
|
+
msg = msg % args if args
|
118
|
+
msg = "'#{val.to_s.gsub(/\n/, '\n')}': #{msg}" if !val.nil? && Types.scalar?(val)
|
119
|
+
return msg;
|
120
|
+
end
|
121
|
+
module_function :_build_message
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
extend ErrorHelper
|
104
126
|
|
105
127
|
end
|