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
@@ -56,7 +56,7 @@
|
|
56
56
|
</tr>
|
57
57
|
<tr class="top-aligned-row">
|
58
58
|
<td><strong>Last Update:</strong></td>
|
59
|
-
<td>
|
59
|
+
<td>Thu Jan 17 21:21:16 +0900 2008</td>
|
60
60
|
</tr>
|
61
61
|
</table>
|
62
62
|
</div>
|
@@ -70,7 +70,7 @@
|
|
70
70
|
|
71
71
|
<div id="description">
|
72
72
|
<p>
|
73
|
-
$Rev:
|
73
|
+
$Rev: 81 $ $Release: 0.7.0 $ copyright(c) 2005-2008 kuwata-lab all rights reserved.
|
74
74
|
</p>
|
75
75
|
|
76
76
|
</div>
|
@@ -56,7 +56,7 @@
|
|
56
56
|
</tr>
|
57
57
|
<tr class="top-aligned-row">
|
58
58
|
<td><strong>Last Update:</strong></td>
|
59
|
-
<td>Sun
|
59
|
+
<td>Sun Jan 27 22:49:22 +0900 2008</td>
|
60
60
|
</tr>
|
61
61
|
</table>
|
62
62
|
</div>
|
@@ -70,7 +70,8 @@
|
|
70
70
|
|
71
71
|
<div id="description">
|
72
72
|
<p>
|
73
|
-
$Rev:
|
73
|
+
$Rev: 95 $ $Release: 0.7.0 $ copyright(c) 2006 kuwata-lab.com all rights
|
74
|
+
reserved.
|
74
75
|
</p>
|
75
76
|
|
76
77
|
</div>
|
data/doc-api/fr_class_index.html
CHANGED
@@ -25,9 +25,11 @@
|
|
25
25
|
<a href="classes/Kwalify.html">Kwalify</a><br />
|
26
26
|
<a href="classes/Kwalify/AssertionError.html">Kwalify::AssertionError</a><br />
|
27
27
|
<a href="classes/Kwalify/BaseError.html">Kwalify::BaseError</a><br />
|
28
|
+
<a href="classes/Kwalify/BaseParser.html">Kwalify::BaseParser</a><br />
|
28
29
|
<a href="classes/Kwalify/CommandOptionError.html">Kwalify::CommandOptionError</a><br />
|
29
30
|
<a href="classes/Kwalify/ErrorHelper.html">Kwalify::ErrorHelper</a><br />
|
30
31
|
<a href="classes/Kwalify/HashInterface.html">Kwalify::HashInterface</a><br />
|
32
|
+
<a href="classes/Kwalify/Json.html">Kwalify::Json</a><br />
|
31
33
|
<a href="classes/Kwalify/KwalifyError.html">Kwalify::KwalifyError</a><br />
|
32
34
|
<a href="classes/Kwalify/Main.html">Kwalify::Main</a><br />
|
33
35
|
<a href="classes/Kwalify/MetaValidator.html">Kwalify::MetaValidator</a><br />
|
@@ -36,14 +38,19 @@
|
|
36
38
|
<a href="classes/Kwalify/PlainYamlParser/Alias.html">Kwalify::PlainYamlParser::Alias</a><br />
|
37
39
|
<a href="classes/Kwalify/Rule.html">Kwalify::Rule</a><br />
|
38
40
|
<a href="classes/Kwalify/SchemaError.html">Kwalify::SchemaError</a><br />
|
41
|
+
<a href="classes/Kwalify/SyntaxError.html">Kwalify::SyntaxError</a><br />
|
39
42
|
<a href="classes/Kwalify/Types.html">Kwalify::Types</a><br />
|
43
|
+
<a href="classes/Kwalify/Util.html">Kwalify::Util</a><br />
|
44
|
+
<a href="classes/Kwalify/Util/HashLike.html">Kwalify::Util::HashLike</a><br />
|
45
|
+
<a href="classes/Kwalify/Util/OrderedHash.html">Kwalify::Util::OrderedHash</a><br />
|
40
46
|
<a href="classes/Kwalify/ValidationError.html">Kwalify::ValidationError</a><br />
|
41
47
|
<a href="classes/Kwalify/Validator.html">Kwalify::Validator</a><br />
|
48
|
+
<a href="classes/Kwalify/Yaml.html">Kwalify::Yaml</a><br />
|
49
|
+
<a href="classes/Kwalify/Yaml/Parser.html">Kwalify::Yaml::Parser</a><br />
|
42
50
|
<a href="classes/Kwalify/YamlParser.html">Kwalify::YamlParser</a><br />
|
43
51
|
<a href="classes/Kwalify/YamlSyntaxError.html">Kwalify::YamlSyntaxError</a><br />
|
44
52
|
<a href="classes/Test.html">Test</a><br />
|
45
53
|
<a href="classes/Test/Unit.html">Test::Unit</a><br />
|
46
|
-
<a href="classes/YamlHelper.html">YamlHelper</a><br />
|
47
54
|
</div>
|
48
55
|
</div>
|
49
56
|
</body>
|
data/doc-api/fr_file_index.html
CHANGED
@@ -26,13 +26,17 @@
|
|
26
26
|
<a href="files/kwalify/main_rb.html">kwalify/main.rb</a><br />
|
27
27
|
<a href="files/kwalify/messages_rb.html">kwalify/messages.rb</a><br />
|
28
28
|
<a href="files/kwalify/meta-validator_rb.html">kwalify/meta-validator.rb</a><br />
|
29
|
+
<a href="files/kwalify/parser/base_rb.html">kwalify/parser/base.rb</a><br />
|
30
|
+
<a href="files/kwalify/parser/yaml_rb.html">kwalify/parser/yaml.rb</a><br />
|
29
31
|
<a href="files/kwalify/rule_rb.html">kwalify/rule.rb</a><br />
|
30
32
|
<a href="files/kwalify/types_rb.html">kwalify/types.rb</a><br />
|
33
|
+
<a href="files/kwalify/util_rb.html">kwalify/util.rb</a><br />
|
31
34
|
<a href="files/kwalify/util/assert-text-equal_rb.html">kwalify/util/assert-text-equal.rb</a><br />
|
32
35
|
<a href="files/kwalify/util/hash-interface_rb.html">kwalify/util/hash-interface.rb</a><br />
|
36
|
+
<a href="files/kwalify/util/hashlike_rb.html">kwalify/util/hashlike.rb</a><br />
|
33
37
|
<a href="files/kwalify/util/option-parser_rb.html">kwalify/util/option-parser.rb</a><br />
|
38
|
+
<a href="files/kwalify/util/ordered-hash_rb.html">kwalify/util/ordered-hash.rb</a><br />
|
34
39
|
<a href="files/kwalify/util/testcase-helper_rb.html">kwalify/util/testcase-helper.rb</a><br />
|
35
|
-
<a href="files/kwalify/util/yaml-helper_rb.html">kwalify/util/yaml-helper.rb</a><br />
|
36
40
|
<a href="files/kwalify/validator_rb.html">kwalify/validator.rb</a><br />
|
37
41
|
<a href="files/kwalify/yaml-parser_rb.html">kwalify/yaml-parser.rb</a><br />
|
38
42
|
</div>
|
@@ -20,88 +20,147 @@
|
|
20
20
|
<div id="index">
|
21
21
|
<h1 class="section-bar">Methods</h1>
|
22
22
|
<div id="index-entries">
|
23
|
-
<a href="classes/Kwalify/BaseError.html#
|
24
|
-
<a href="classes/Kwalify/
|
25
|
-
<a href="classes/Kwalify/
|
26
|
-
<a href="classes/Kwalify/
|
27
|
-
<a href="classes/Kwalify/
|
28
|
-
<a href="classes/Kwalify/
|
29
|
-
<a href="classes/Kwalify/
|
30
|
-
<a href="classes/Kwalify/
|
31
|
-
<a href="classes/Kwalify/
|
32
|
-
<a href="classes/Kwalify/
|
33
|
-
<a href="classes/Kwalify/
|
34
|
-
<a href="classes/Kwalify/
|
35
|
-
<a href="classes/Kwalify/
|
23
|
+
<a href="classes/Kwalify/BaseError.html#M000084"><=> (Kwalify::BaseError)</a><br />
|
24
|
+
<a href="classes/Kwalify/Util/HashLike.html#M000025">[] (Kwalify::Util::HashLike)</a><br />
|
25
|
+
<a href="classes/Kwalify/Util/HashLike.html#M000026">[]= (Kwalify::Util::HashLike)</a><br />
|
26
|
+
<a href="classes/Kwalify/Util/OrderedHash.html#M000033">[]= (Kwalify::Util::OrderedHash)</a><br />
|
27
|
+
<a href="classes/Kwalify/ErrorHelper.html#M000018">_build_message (Kwalify::ErrorHelper)</a><br />
|
28
|
+
<a href="classes/Kwalify/BaseParser.html#M000098">_getch (Kwalify::BaseParser)</a><br />
|
29
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000071">_getclass (Kwalify::Yaml::Parser)</a><br />
|
30
|
+
<a href="classes/Kwalify/Rule.html#M000118">_init (Kwalify::Rule)</a><br />
|
31
|
+
<a href="classes/Kwalify/Validator.html#M000075">_inspect (Kwalify::Validator)</a><br />
|
32
|
+
<a href="classes/Kwalify/Main.html#M000088">_inspect (Kwalify::Main)</a><br />
|
33
|
+
<a href="classes/Kwalify/Rule.html#M000120">_inspect (Kwalify::Rule)</a><br />
|
34
|
+
<a href="classes/Kwalify/BaseParser.html#M000093">_set_column_and_linenum (Kwalify::BaseParser)</a><br />
|
35
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000042">_set_error_info (Kwalify::Yaml::Parser)</a><br />
|
36
|
+
<a href="classes/Kwalify/BaseParser.html#M000100">_syntax_error (Kwalify::BaseParser)</a><br />
|
37
|
+
<a href="classes/Kwalify/Validator.html#M000078">_validate (Kwalify::Validator)</a><br />
|
38
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000057">_validate_map_value (Kwalify::Yaml::Parser)</a><br />
|
39
|
+
<a href="classes/Kwalify/Validator.html#M000079">_validate_unique (Kwalify::Validator)</a><br />
|
40
|
+
<a href="classes/Kwalify/Util/OrderedHash.html#M000032">add (Kwalify::Util::OrderedHash)</a><br />
|
41
|
+
<a href="classes/Kwalify/PlainYamlParser.html#M000135">add_to_map (Kwalify::PlainYamlParser)</a><br />
|
42
|
+
<a href="classes/Kwalify/YamlParser.html#M000112">add_to_map (Kwalify::YamlParser)</a><br />
|
43
|
+
<a href="classes/Kwalify/PlainYamlParser.html#M000132">add_to_seq (Kwalify::PlainYamlParser)</a><br />
|
44
|
+
<a href="classes/Kwalify/YamlParser.html#M000109">add_to_seq (Kwalify::YamlParser)</a><br />
|
45
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000069">add_to_seq (Kwalify::Yaml::Parser)</a><br />
|
46
|
+
<a href="classes/Kwalify/ErrorHelper.html#M000015">assert_error (Kwalify::ErrorHelper)</a><br />
|
36
47
|
<a href="classes/Kwalify/Types.html#M000011">collection? (Kwalify::Types)</a><br />
|
37
48
|
<a href="classes/Kwalify/Types.html#M000013">collection_type? (Kwalify::Types)</a><br />
|
38
|
-
<a href="classes/
|
39
|
-
<a href="classes/Kwalify/
|
40
|
-
<a href="classes/Kwalify/
|
41
|
-
<a href="classes/Kwalify/
|
42
|
-
<a href="classes/Kwalify/
|
43
|
-
<a href="classes/Kwalify/
|
44
|
-
<a href="classes/Kwalify/
|
45
|
-
<a href="classes/Kwalify/
|
46
|
-
<a href="classes/Kwalify/PlainYamlParser.html#
|
47
|
-
<a href="classes/Kwalify/
|
48
|
-
<a href="classes/Kwalify/
|
49
|
-
<a href="classes/Kwalify/
|
49
|
+
<a href="classes/Kwalify/Util.html#M000023">create_hashtable (Kwalify::Util)</a><br />
|
50
|
+
<a href="classes/Kwalify/YamlParser.html#M000111">create_mapping (Kwalify::YamlParser)</a><br />
|
51
|
+
<a href="classes/Kwalify/PlainYamlParser.html#M000134">create_mapping (Kwalify::PlainYamlParser)</a><br />
|
52
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000067">create_mapping (Kwalify::Yaml::Parser)</a><br />
|
53
|
+
<a href="classes/Kwalify/YamlParser.html#M000116">create_scalar (Kwalify::YamlParser)</a><br />
|
54
|
+
<a href="classes/Kwalify/PlainYamlParser.html#M000139">create_scalar (Kwalify::PlainYamlParser)</a><br />
|
55
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000068">create_scalar (Kwalify::Yaml::Parser)</a><br />
|
56
|
+
<a href="classes/Kwalify/YamlParser.html#M000108">create_sequence (Kwalify::YamlParser)</a><br />
|
57
|
+
<a href="classes/Kwalify/PlainYamlParser.html#M000131">create_sequence (Kwalify::PlainYamlParser)</a><br />
|
58
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000066">create_sequence (Kwalify::Yaml::Parser)</a><br />
|
59
|
+
<a href="classes/Kwalify/PlainYamlParser.html#M000140">current_line (Kwalify::PlainYamlParser)</a><br />
|
60
|
+
<a href="classes/Kwalify/PlainYamlParser.html#M000141">current_linenum (Kwalify::PlainYamlParser)</a><br />
|
61
|
+
<a href="classes/Kwalify/Main.html#M000087">debug? (Kwalify::Main)</a><br />
|
62
|
+
<a href="classes/Kwalify/Util/OrderedHash.html#M000036">delete (Kwalify::Util::OrderedHash)</a><br />
|
63
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000044">document_start? (Kwalify::Yaml::Parser)</a><br />
|
64
|
+
<a href="classes/Kwalify/Util/OrderedHash.html#M000037">each (Kwalify::Util::OrderedHash)</a><br />
|
65
|
+
<a href="classes/Kwalify/Util/HashLike.html#M000029">each (Kwalify::Util::HashLike)</a><br />
|
66
|
+
<a href="classes/Kwalify/BaseParser.html#M000096">eos? (Kwalify::BaseParser)</a><br />
|
67
|
+
<a href="classes/Kwalify/Main.html#M000089">execute (Kwalify::Main)</a><br />
|
68
|
+
<a href="classes/Kwalify/Util.html#M000022">get_class (Kwalify::Util)</a><br />
|
69
|
+
<a href="classes/Kwalify/Rule.html#M000119">get_init_method (Kwalify::Rule)</a><br />
|
50
70
|
<a href="classes/Kwalify/Types.html#M000010">get_type_class (Kwalify::Types)</a><br />
|
51
|
-
<a href="classes/
|
52
|
-
<a href="classes/Kwalify/
|
53
|
-
<a href="classes/Kwalify/
|
54
|
-
<a href="classes/Kwalify/
|
55
|
-
<a href="classes/Kwalify/
|
56
|
-
<a href="classes/Kwalify/
|
57
|
-
<a href="classes/Kwalify/
|
58
|
-
<a href="classes/Kwalify/
|
59
|
-
<a href="classes/Kwalify/
|
60
|
-
<a href="classes/Kwalify/
|
71
|
+
<a href="classes/Kwalify/Util.html#M000024">get_value (Kwalify::Util)</a><br />
|
72
|
+
<a href="classes/Kwalify/BaseParser.html#M000095">group (Kwalify::BaseParser)</a><br />
|
73
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000046">has_next? (Kwalify::Yaml::Parser)</a><br />
|
74
|
+
<a href="classes/Kwalify/PlainYamlParser.html#M000129">has_next? (Kwalify::PlainYamlParser)</a><br />
|
75
|
+
<a href="classes/Kwalify/MetaValidator.html#M000121">instance (Kwalify::MetaValidator)</a><br />
|
76
|
+
<a href="classes/Kwalify/Util/HashLike.html#M000028">key? (Kwalify::Util::HashLike)</a><br />
|
77
|
+
<a href="classes/Kwalify/Util/HashLike.html#M000027">key? (Kwalify::Util::HashLike)</a><br />
|
78
|
+
<a href="classes/Kwalify/Util/OrderedHash.html#M000034">keys (Kwalify::Util::OrderedHash)</a><br />
|
79
|
+
<a href="classes/Kwalify/Yaml.html#M000038">load (Kwalify::Yaml)</a><br />
|
80
|
+
<a href="classes/Kwalify/Yaml.html#M000039">load_file (Kwalify::Yaml)</a><br />
|
81
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000072">location (Kwalify::Yaml::Parser)</a><br />
|
82
|
+
<a href="classes/Kwalify/Main.html#M000090">main (Kwalify::Main)</a><br />
|
83
|
+
<a href="classes/Kwalify/BaseParser.html#M000094">match? (Kwalify::BaseParser)</a><br />
|
84
|
+
<a href="classes/Kwalify/YamlParser.html#M000115">merge_map (Kwalify::YamlParser)</a><br />
|
85
|
+
<a href="classes/Kwalify/PlainYamlParser.html#M000138">merge_map (Kwalify::PlainYamlParser)</a><br />
|
86
|
+
<a href="classes/Kwalify/SyntaxError.html#M000102">message (Kwalify::SyntaxError)</a><br />
|
61
87
|
<a href="classes/Kwalify.html#M000007">meta_validator (Kwalify)</a><br />
|
62
88
|
<a href="classes/Kwalify.html#M000005">msg (Kwalify)</a><br />
|
63
|
-
<a href="classes/Kwalify/AssertionError.html#M000062">new (Kwalify::AssertionError)</a><br />
|
64
|
-
<a href="classes/Kwalify/YamlParser.html#M000042">new (Kwalify::YamlParser)</a><br />
|
65
89
|
<a href="classes/CommandOptionError.html#M000001">new (CommandOptionError)</a><br />
|
90
|
+
<a href="classes/Kwalify/PlainYamlParser/Alias.html#M000142">new (Kwalify::PlainYamlParser::Alias)</a><br />
|
91
|
+
<a href="classes/Kwalify/YamlParser.html#M000103">new (Kwalify::YamlParser)</a><br />
|
66
92
|
<a href="classes/CommandOptionParser.html#M000002">new (CommandOptionParser)</a><br />
|
67
|
-
<a href="classes/Kwalify/
|
68
|
-
<a href="classes/Kwalify/
|
69
|
-
<a href="classes/Kwalify/
|
70
|
-
<a href="classes/Kwalify/
|
71
|
-
<a href="classes/Kwalify/
|
72
|
-
<a href="classes/Kwalify/
|
73
|
-
<a href="classes/Kwalify/
|
74
|
-
<a href="classes/Kwalify/
|
75
|
-
<a href="classes/Kwalify/
|
76
|
-
<a href="classes/Kwalify/
|
77
|
-
<a href="classes/Kwalify/
|
78
|
-
<a href="classes/Kwalify/
|
79
|
-
<a href="classes/Kwalify/
|
80
|
-
<a href="classes/Kwalify/
|
93
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000040">new (Kwalify::Yaml::Parser)</a><br />
|
94
|
+
<a href="classes/Kwalify/Util/OrderedHash.html#M000030">new (Kwalify::Util::OrderedHash)</a><br />
|
95
|
+
<a href="classes/Kwalify/Rule.html#M000117">new (Kwalify::Rule)</a><br />
|
96
|
+
<a href="classes/Kwalify/Validator.html#M000074">new (Kwalify::Validator)</a><br />
|
97
|
+
<a href="classes/Kwalify/PlainYamlParser.html#M000127">new (Kwalify::PlainYamlParser)</a><br />
|
98
|
+
<a href="classes/Kwalify/ValidationError.html#M000126">new (Kwalify::ValidationError)</a><br />
|
99
|
+
<a href="classes/Kwalify/CommandOptionError.html#M000125">new (Kwalify::CommandOptionError)</a><br />
|
100
|
+
<a href="classes/Kwalify/Main.html#M000086">new (Kwalify::Main)</a><br />
|
101
|
+
<a href="classes/Kwalify/Parser.html#M000085">new (Kwalify::Parser)</a><br />
|
102
|
+
<a href="classes/Kwalify/SchemaError.html#M000080">new (Kwalify::SchemaError)</a><br />
|
103
|
+
<a href="classes/Kwalify/BaseError.html#M000081">new (Kwalify::BaseError)</a><br />
|
104
|
+
<a href="classes/Kwalify/AssertionError.html#M000124">new (Kwalify::AssertionError)</a><br />
|
105
|
+
<a href="classes/Kwalify/MetaValidator.html#M000122">new (Kwalify::MetaValidator)</a><br />
|
106
|
+
<a href="classes/Kwalify/SyntaxError.html#M000101">new (Kwalify::SyntaxError)</a><br />
|
81
107
|
<a href="classes/CommandOptionParser.html#M000004">parse (CommandOptionParser)</a><br />
|
82
|
-
<a href="classes/Kwalify/
|
83
|
-
<a href="classes/Kwalify/
|
84
|
-
<a href="classes/Kwalify/
|
108
|
+
<a href="classes/Kwalify/YamlParser.html#M000104">parse (Kwalify::YamlParser)</a><br />
|
109
|
+
<a href="classes/Kwalify/PlainYamlParser.html#M000128">parse (Kwalify::PlainYamlParser)</a><br />
|
110
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000047">parse (Kwalify::Yaml::Parser)</a><br />
|
111
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000053">parse_alias (Kwalify::Yaml::Parser)</a><br />
|
112
|
+
<a href="classes/Kwalify/PlainYamlParser.html#M000130">parse_all (Kwalify::PlainYamlParser)</a><br />
|
113
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000052">parse_anchor (Kwalify::Yaml::Parser)</a><br />
|
114
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000058">parse_block_map (Kwalify::Yaml::Parser)</a><br />
|
115
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000059">parse_block_scalar (Kwalify::Yaml::Parser)</a><br />
|
116
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000056">parse_block_seq (Kwalify::Yaml::Parser)</a><br />
|
117
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000060">parse_block_text (Kwalify::Yaml::Parser)</a><br />
|
118
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000055">parse_block_value (Kwalify::Yaml::Parser)</a><br />
|
119
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000051">parse_documents (Kwalify::Yaml::Parser)</a><br />
|
120
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000048">parse_file (Kwalify::Yaml::Parser)</a><br />
|
121
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000063">parse_flow_map (Kwalify::Yaml::Parser)</a><br />
|
122
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000064">parse_flow_scalar (Kwalify::Yaml::Parser)</a><br />
|
123
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000062">parse_flow_seq (Kwalify::Yaml::Parser)</a><br />
|
124
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000061">parse_flow_value (Kwalify::Yaml::Parser)</a><br />
|
125
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000049">parse_next (Kwalify::Yaml::Parser)</a><br />
|
126
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000050">parse_stream (Kwalify::Yaml::Parser)</a><br />
|
127
|
+
<a href="classes/Kwalify/BaseError.html#M000082">path (Kwalify::BaseError)</a><br />
|
128
|
+
<a href="classes/Kwalify/YamlParser.html#M000105">path_linenum (Kwalify::YamlParser)</a><br />
|
129
|
+
<a href="classes/Kwalify/BaseParser.html#M000097">peep (Kwalify::BaseParser)</a><br />
|
130
|
+
<a href="classes/Kwalify/Util/OrderedHash.html#M000031">put (Kwalify::Util::OrderedHash)</a><br />
|
131
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000070">put_to_map (Kwalify::Yaml::Parser)</a><br />
|
132
|
+
<a href="classes/Kwalify/BaseParser.html#M000091">reset (Kwalify::BaseParser)</a><br />
|
133
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000041">reset_parser (Kwalify::Yaml::Parser)</a><br />
|
134
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000054">resolve_preceding_aliases (Kwalify::Yaml::Parser)</a><br />
|
85
135
|
<a href="classes/Kwalify/Types.html#M000012">scalar? (Kwalify::Types)</a><br />
|
86
136
|
<a href="classes/Kwalify/Types.html#M000014">scalar_type? (Kwalify::Types)</a><br />
|
87
|
-
<a href="classes/Kwalify/
|
88
|
-
<a href="classes/Kwalify/
|
89
|
-
<a href="classes/Kwalify/
|
90
|
-
<a href="classes/Kwalify/
|
91
|
-
<a href="classes/Kwalify/YamlParser.html#
|
92
|
-
<a href="classes/Kwalify/YamlParser.html#
|
93
|
-
<a href="classes/Kwalify/
|
94
|
-
<a href="classes/Kwalify/
|
95
|
-
<a href="classes/Kwalify/
|
96
|
-
<a href="classes/Kwalify/
|
137
|
+
<a href="classes/Kwalify/BaseParser.html#M000092">scan (Kwalify::BaseParser)</a><br />
|
138
|
+
<a href="classes/Kwalify/BaseParser.html#M000099">scan_string (Kwalify::BaseParser)</a><br />
|
139
|
+
<a href="classes/Kwalify/ErrorHelper.html#M000017">schema_error (Kwalify::ErrorHelper)</a><br />
|
140
|
+
<a href="classes/Kwalify/PlainYamlParser.html#M000137">set_default (Kwalify::PlainYamlParser)</a><br />
|
141
|
+
<a href="classes/Kwalify/YamlParser.html#M000114">set_default (Kwalify::YamlParser)</a><br />
|
142
|
+
<a href="classes/Kwalify/YamlParser.html#M000107">set_error_linenums (Kwalify::YamlParser)</a><br />
|
143
|
+
<a href="classes/Kwalify/YamlParser.html#M000106">set_errors_linenum (Kwalify::YamlParser)</a><br />
|
144
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000073">set_errors_linenum (Kwalify::Yaml::Parser)</a><br />
|
145
|
+
<a href="classes/Kwalify/YamlParser.html#M000113">set_map_with (Kwalify::YamlParser)</a><br />
|
146
|
+
<a href="classes/Kwalify/PlainYamlParser.html#M000136">set_map_with (Kwalify::PlainYamlParser)</a><br />
|
147
|
+
<a href="classes/Kwalify/YamlParser.html#M000110">set_seq_at (Kwalify::YamlParser)</a><br />
|
148
|
+
<a href="classes/Kwalify/PlainYamlParser.html#M000133">set_seq_at (Kwalify::PlainYamlParser)</a><br />
|
149
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000043">skip_spaces_and_comments (Kwalify::Yaml::Parser)</a><br />
|
150
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000045">stream_end? (Kwalify::Yaml::Parser)</a><br />
|
151
|
+
<a href="classes/Kwalify/BaseError.html#M000083">to_s (Kwalify::BaseError)</a><br />
|
152
|
+
<a href="classes/Kwalify/Yaml/Parser.html#M000065">to_scalar (Kwalify::Yaml::Parser)</a><br />
|
97
153
|
<a href="classes/CommandOptionParser.html#M000003">to_value (CommandOptionParser)</a><br />
|
154
|
+
<a href="classes/Kwalify/Util.html#M000021">traverse_rule (Kwalify::Util)</a><br />
|
155
|
+
<a href="classes/Kwalify/Util.html#M000020">traverse_schema (Kwalify::Util)</a><br />
|
98
156
|
<a href="classes/Kwalify/Types.html#M000009">type_class (Kwalify::Types)</a><br />
|
99
157
|
<a href="classes/Kwalify/Types.html#M000008">type_table (Kwalify::Types)</a><br />
|
100
|
-
<a href="classes/
|
101
|
-
<a href="classes/Kwalify/Validator.html#
|
102
|
-
<a href="classes/Kwalify/ErrorHelper.html#
|
103
|
-
<a href="classes/Kwalify/MetaValidator.html#
|
104
|
-
<a href="classes/Kwalify/Validator.html#
|
158
|
+
<a href="classes/Kwalify/Util.html#M000019">untabify (Kwalify::Util)</a><br />
|
159
|
+
<a href="classes/Kwalify/Validator.html#M000076">validate (Kwalify::Validator)</a><br />
|
160
|
+
<a href="classes/Kwalify/ErrorHelper.html#M000016">validate_error (Kwalify::ErrorHelper)</a><br />
|
161
|
+
<a href="classes/Kwalify/MetaValidator.html#M000123">validate_hook (Kwalify::MetaValidator)</a><br />
|
162
|
+
<a href="classes/Kwalify/Validator.html#M000077">validate_hook (Kwalify::Validator)</a><br />
|
163
|
+
<a href="classes/Kwalify/Util/OrderedHash.html#M000035">values (Kwalify::Util::OrderedHash)</a><br />
|
105
164
|
<a href="classes/Kwalify.html#M000006">word (Kwalify)</a><br />
|
106
165
|
</div>
|
107
166
|
</div>
|
data/doc/img/fig01.png
ADDED
Binary file
|
data/doc/users-guide.html
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
<html>
|
3
3
|
<head>
|
4
4
|
<meta http-equiv="Content-Type" content="text/html">
|
5
|
-
<title>Kwalify
|
5
|
+
<title>Kwalify User's Guide (for Ruby)</title>
|
6
6
|
<meta name="author" content="makoto kuwata <kwa(at)kuwata-lab.com>">
|
7
7
|
<meta name="generator" content="kwaser">
|
8
8
|
<meta http-equiv="Content-Style-Type" content="text/css">
|
@@ -12,51 +12,29 @@
|
|
12
12
|
|
13
13
|
<div class="mainbody">
|
14
14
|
|
15
|
-
<div align="left"><h1>Kwalify
|
15
|
+
<div align="left"><h1>Kwalify User's Guide (for Ruby)</h1></div>
|
16
16
|
<div align="left">
|
17
17
|
makoto kuwata <kwa(at)kuwata-lab.com><br>
|
18
|
-
last update: $Date:
|
18
|
+
last update: $Date: 2008-01-27 22:57:22 +0900 (Sun, 27 Jan 2008) $<br>
|
19
19
|
</div>
|
20
20
|
|
21
21
|
<a name="preface"></a>
|
22
22
|
<h2 class="section1">Preface</h2>
|
23
|
-
<p>Kwalify<sup>(<a href="#fnref:1" name="fnlink:1">*1</a>)</sup> is a
|
23
|
+
<p>Kwalify<sup>(<a href="#fnref:1" name="fnlink:1">*1</a>)</sup> is a parser, schema validator, and data binding tool for YAML and JSON.
|
24
|
+
Kwalify enables you to handle YAML and JSON more easily and strictly.
|
24
25
|
</p>
|
25
|
-
<p>
|
26
|
-
Kwalify is based on a new "50-5 rule" which suggests that 5% of the population owns 50% of the wealth.
|
27
|
-
This rule is more aggressive and cost-effective than Pareto Law. The rule is named as "Levi's Law".
|
28
|
-
</p>
|
29
|
-
<div align="center">
|
30
|
-
<table class="table1" border="1" cellspacing="0">
|
31
|
-
<tr class="tr1">
|
32
|
-
<th class="th1">schema technology</th>
|
33
|
-
<th class="th1">(A) cover range</th>
|
34
|
-
<th class="th1">(B) cost to pay</th>
|
35
|
-
<th class="th1">(A)/(B) effectiveness</th>
|
36
|
-
</tr>
|
37
|
-
<tr class="tr1">
|
38
|
-
<td class="td1">XML Schema</td>
|
39
|
-
<td class="td1">95%</td>
|
40
|
-
<td class="td1">100%</td>
|
41
|
-
<td class="td1">0.95 (= 95/100)</td>
|
42
|
-
</tr>
|
43
|
-
<tr class="tr1">
|
44
|
-
<td class="td1">RelaxNG</td>
|
45
|
-
<td class="td1">80%</td>
|
46
|
-
<td class="td1">20%</td>
|
47
|
-
<td class="td1">4.0 (= 80/20)</td>
|
48
|
-
</tr>
|
49
|
-
<tr class="tr1">
|
50
|
-
<td class="td1">Kwalify</td>
|
51
|
-
<td class="td1">50%</td>
|
52
|
-
<td class="td1">5%</td>
|
53
|
-
<td class="td1">10.0 (= 50/5)</td>
|
54
|
-
</tr>
|
55
|
-
</table>
|
56
|
-
</div>
|
57
|
-
<p>Kwalify is small and in fact poorer than RelaxNG or XML Schema.
|
58
|
-
I hope you extend/customize Kwalify for your own way.
|
26
|
+
<p>Topics:
|
59
27
|
</p>
|
28
|
+
<ul type="disc">
|
29
|
+
<li><a href="#schema">Schema validation for YAML</a> and <a href="#tips-json">JSON</a>
|
30
|
+
</li>
|
31
|
+
<li><a href="#actions">Class definition generation for Ruby, PHP, and Java</a>
|
32
|
+
</li>
|
33
|
+
<li><a href="#howto-databinding">Data binding</a>
|
34
|
+
</li>
|
35
|
+
<li><a href="#howto-preceding">Preceding alias</a>
|
36
|
+
</li>
|
37
|
+
</ul>
|
60
38
|
<div class="footnote">
|
61
39
|
<dl compact>
|
62
40
|
<dt>(<a name="fnref:1" href="#fnlink:1">*1</a>)</dt>
|
@@ -82,23 +60,17 @@ I hope you extend/customize Kwalify for your own way.
|
|
82
60
|
</li>
|
83
61
|
<li><a href="#schema-map-of-seq">Mapping of Sequence</a>
|
84
62
|
</li>
|
85
|
-
<li><a href="#schema-rules">Rule and
|
63
|
+
<li><a href="#schema-rules">Rule and Constraint</a>
|
86
64
|
</li>
|
87
65
|
<li><a href="#schema-unique">Unique constraint</a>
|
88
66
|
</li>
|
89
|
-
<li><a href="#schema-hook">Validator#validator_hook()</a>
|
90
|
-
</li>
|
91
|
-
<li><a href="#schema-block">Validator with Block</a>
|
92
|
-
</li>
|
93
67
|
</ul>
|
94
68
|
</li>
|
95
69
|
<li><a href="#tips">Tips</a>
|
96
70
|
<ul>
|
97
|
-
<li><a href="#tips-quotes">Enclose Key Names in (Double) Quotes</a>
|
98
|
-
</li>
|
99
71
|
<li><a href="#tips-json">JSON</a>
|
100
72
|
</li>
|
101
|
-
<li><a href="#tips-anchor">Anchor</a>
|
73
|
+
<li><a href="#tips-anchor">Anchor and Alias</a>
|
102
74
|
</li>
|
103
75
|
<li><a href="#tips-default">Default of Mapping</a>
|
104
76
|
</li>
|
@@ -106,6 +78,22 @@ I hope you extend/customize Kwalify for your own way.
|
|
106
78
|
</li>
|
107
79
|
</ul>
|
108
80
|
</li>
|
81
|
+
<li><a href="#howto">How to in Ruby</a>
|
82
|
+
<ul>
|
83
|
+
<li><a href="#howot-validate">Validation</a>
|
84
|
+
</li>
|
85
|
+
<li><a href="#howto-parse">Parsing with Validation</a>
|
86
|
+
</li>
|
87
|
+
<li><a href="#howto-meta">Meta Validation</a>
|
88
|
+
</li>
|
89
|
+
<li><a href="#howto-hook">Validator#validator_hook()</a>
|
90
|
+
</li>
|
91
|
+
<li><a href="#howto-preceding">Preceding Alias</a>
|
92
|
+
</li>
|
93
|
+
<li><a href="#howto-databinding">Data Binding</a>
|
94
|
+
</li>
|
95
|
+
</ul>
|
96
|
+
</li>
|
109
97
|
<li><a href="#actions">Actions</a>
|
110
98
|
<ul>
|
111
99
|
<li><a href="#action-genclass">Class Definition Generation</a>
|
@@ -118,13 +106,9 @@ I hope you extend/customize Kwalify for your own way.
|
|
118
106
|
</li>
|
119
107
|
</ul>
|
120
108
|
</li>
|
121
|
-
<li><a href="#
|
109
|
+
<li><a href="#ref">References</a>
|
122
110
|
<ul>
|
123
|
-
<li><a href="#
|
124
|
-
</li>
|
125
|
-
<li><a href="#usage-ruby">Usage in Ruby Script</a>
|
126
|
-
</li>
|
127
|
-
<li><a href="#usage-java">Usage in Java Program</a>
|
111
|
+
<li><a href="#ref-usage">Usage in Command-Line</a>
|
128
112
|
</li>
|
129
113
|
</ul>
|
130
114
|
</li>
|
@@ -137,6 +121,8 @@ I hope you extend/customize Kwalify for your own way.
|
|
137
121
|
|
138
122
|
<a name="schema"></a>
|
139
123
|
<h2 class="section1">Schema Definition</h2>
|
124
|
+
<p>This section describes how to define schema definition of YAML.
|
125
|
+
</p>
|
140
126
|
<a name="schema-seq"></a>
|
141
127
|
<h3 class="section2">Sequence</h3>
|
142
128
|
<a name="schema01.yaml"></a>
|
@@ -153,7 +139,7 @@ sequence:
|
|
153
139
|
- bar
|
154
140
|
- baz
|
155
141
|
</pre>
|
156
|
-
<a name="valid01.
|
142
|
+
<a name="valid01.result"></a>
|
157
143
|
<div class="terminal_caption">
|
158
144
|
validate</div>
|
159
145
|
<pre class="terminal">$ kwalify -lf schema01.yaml document01a.yaml
|
@@ -166,7 +152,7 @@ document01a.yaml#0: valid.
|
|
166
152
|
- 123
|
167
153
|
- baz
|
168
154
|
</pre>
|
169
|
-
<a name="invalid01.
|
155
|
+
<a name="invalid01.result"></a>
|
170
156
|
<div class="terminal_caption">
|
171
157
|
validate</div>
|
172
158
|
<pre class="terminal">$ kwalify -lf schema01.yaml document01b.yaml
|
@@ -185,15 +171,15 @@ document01b.yaml#0: INVALID
|
|
185
171
|
<code>schema02.yaml</code> : mapping of scalar</div>
|
186
172
|
<pre class="program">type: map
|
187
173
|
mapping:
|
188
|
-
|
174
|
+
"name":
|
189
175
|
type: str
|
190
176
|
required: yes
|
191
|
-
|
177
|
+
"email":
|
192
178
|
type: str
|
193
179
|
pattern: /@/
|
194
|
-
|
180
|
+
"age":
|
195
181
|
type: int
|
196
|
-
|
182
|
+
"birth":
|
197
183
|
type: date
|
198
184
|
</pre>
|
199
185
|
<a name="document02a.yaml"></a>
|
@@ -204,7 +190,7 @@ email: foo@mail.com
|
|
204
190
|
age: 20
|
205
191
|
birth: 1985-01-01
|
206
192
|
</pre>
|
207
|
-
<a name="valid02.
|
193
|
+
<a name="valid02.result"></a>
|
208
194
|
<div class="terminal_caption">
|
209
195
|
validate</div>
|
210
196
|
<pre class="terminal">$ kwalify -lf schema02.yaml document02a.yaml
|
@@ -218,7 +204,7 @@ email: foo(at)mail.com
|
|
218
204
|
age: twenty
|
219
205
|
birth: Jun 01, 1985
|
220
206
|
</pre>
|
221
|
-
<a name="invalid02.
|
207
|
+
<a name="invalid02.result"></a>
|
222
208
|
<div class="terminal_caption">
|
223
209
|
validate</div>
|
224
210
|
<pre class="terminal">$ kwalify -lf schema02.yaml document02b.yaml
|
@@ -239,10 +225,10 @@ document02b.yaml#0: INVALID
|
|
239
225
|
sequence:
|
240
226
|
- type: map
|
241
227
|
mapping:
|
242
|
-
|
228
|
+
"name":
|
243
229
|
type: str
|
244
230
|
required: true
|
245
|
-
|
231
|
+
"email":
|
246
232
|
type: str
|
247
233
|
</pre>
|
248
234
|
<a name="document03a.yaml"></a>
|
@@ -255,7 +241,7 @@ sequence:
|
|
255
241
|
- name: baz
|
256
242
|
email: baz@mail.org
|
257
243
|
</pre>
|
258
|
-
<a name="valid03.
|
244
|
+
<a name="valid03.result"></a>
|
259
245
|
<div class="terminal_caption">
|
260
246
|
validate</div>
|
261
247
|
<pre class="terminal">$ kwalify -lf schema03.yaml document03a.yaml
|
@@ -271,7 +257,7 @@ document03a.yaml#0: valid.
|
|
271
257
|
- name: baz
|
272
258
|
mail: baz@mail.org
|
273
259
|
</pre>
|
274
|
-
<a name="invalid03.
|
260
|
+
<a name="invalid03.result"></a>
|
275
261
|
<div class="terminal_caption">
|
276
262
|
validate</div>
|
277
263
|
<pre class="terminal">$ kwalify -lf schema03.yaml document03b.yaml
|
@@ -290,23 +276,23 @@ document03b.yaml#0: INVALID
|
|
290
276
|
<code>schema04.yaml</code> : mapping of sequence of mapping</div>
|
291
277
|
<pre class="program">type: map
|
292
278
|
mapping:
|
293
|
-
|
279
|
+
"company":
|
294
280
|
type: str
|
295
281
|
required: yes
|
296
|
-
|
282
|
+
"email":
|
297
283
|
type: str
|
298
|
-
|
284
|
+
"employees":
|
299
285
|
type: seq
|
300
286
|
sequence:
|
301
287
|
- type: map
|
302
288
|
mapping:
|
303
|
-
|
289
|
+
"code":
|
304
290
|
type: int
|
305
291
|
required: yes
|
306
|
-
|
292
|
+
"name":
|
307
293
|
type: str
|
308
294
|
required: yes
|
309
|
-
|
295
|
+
"email":
|
310
296
|
type: str
|
311
297
|
</pre>
|
312
298
|
<a name="document04a.yaml"></a>
|
@@ -322,7 +308,7 @@ employees:
|
|
322
308
|
name: bar
|
323
309
|
email: bar@kuwata-lab.com
|
324
310
|
</pre>
|
325
|
-
<a name="valid04.
|
311
|
+
<a name="valid04.result"></a>
|
326
312
|
<div class="terminal_caption">
|
327
313
|
validate</div>
|
328
314
|
<pre class="terminal">$ kwalify -lf schema04.yaml document04a.yaml
|
@@ -341,7 +327,7 @@ employees:
|
|
341
327
|
name: bar
|
342
328
|
mail: bar@kuwata-lab.com
|
343
329
|
</pre>
|
344
|
-
<a name="invalid04.
|
330
|
+
<a name="invalid04.result"></a>
|
345
331
|
<div class="terminal_caption">
|
346
332
|
validate</div>
|
347
333
|
<pre class="terminal">$ kwalify -lf schema04.yaml document04b.yaml
|
@@ -353,16 +339,28 @@ document04b.yaml#0: INVALID
|
|
353
339
|
|
354
340
|
|
355
341
|
<a name="schema-rules"></a>
|
356
|
-
<h3 class="section2">Rule and
|
357
|
-
<p>
|
342
|
+
<h3 class="section2">Rule and Constraint</h3>
|
343
|
+
<p><code>type:</code>, <code>required:</code>, <code>length</code>, ... are called <strong>constraint</strong> and set of constraints are called <strong>rule</strong>.
|
358
344
|
</p>
|
359
|
-
<
|
345
|
+
<ul type="disc">
|
346
|
+
<li>Rule contains 'type:' constraint. If 'type:' is omitted, 'type: str' is used as default.
|
347
|
+
</li>
|
348
|
+
<li>'sequence:' constraint takes a sequence of rule (the sequence can contain only a rule).
|
349
|
+
</li>
|
350
|
+
<li>'mapping:' constraint takes a mapping which values are rules.
|
351
|
+
</li>
|
352
|
+
</ul>
|
353
|
+
<div style="align:center;">
|
354
|
+
<img src="img/fig01.png" alt="constraints and rules of schema definition." />
|
355
|
+
</div>
|
356
|
+
<p>The following is a list of constraints.
|
360
357
|
</p>
|
361
358
|
<dl class="dl3">
|
362
359
|
<dt class="dt3"><strong>
|
363
360
|
<code>required:</code> </strong></dt>
|
364
361
|
<dd class="dd3">
|
365
362
|
Value is required when true (default is false).
|
363
|
+
This is similar to not-null constraint in RDBMS.
|
366
364
|
</dd>
|
367
365
|
<dt class="dt3"><strong>
|
368
366
|
<code>enum:</code> </strong></dt>
|
@@ -426,23 +424,23 @@ document04b.yaml#0: INVALID
|
|
426
424
|
<dt class="dt3"><strong>
|
427
425
|
<code>length:</code> </strong></dt>
|
428
426
|
<dd class="dd3">
|
429
|
-
Range of length of value between max/max-ex and min/min-ex.
|
427
|
+
Range of length of value between max/max-ex and min/min-ex.
|
428
|
+
Only type <code>str</code> and <code>text</code> are available with <code>length:</code>.
|
430
429
|
</dd>
|
431
430
|
<dt class="dt3"><strong>
|
432
431
|
<code>assert:</code> </strong></dt>
|
433
432
|
<dd class="dd3">
|
434
|
-
String which represents validation expression.
|
435
|
-
|
433
|
+
String which represents validation expression.
|
434
|
+
String should contain variable name <code>val</code> which repsents value.
|
435
|
+
(This is an experimental function and not supported in Kwartz-java).
|
436
436
|
</dd>
|
437
437
|
<dt class="dt3"><strong>
|
438
438
|
<code>unique:</code> </strong></dt>
|
439
439
|
<dd class="dd3">
|
440
|
-
Value is unique for mapping or sequence.
|
440
|
+
Value is unique for mapping or sequence.
|
441
|
+
This is similar to unique constraint of RDBMS.
|
442
|
+
See the next subsection for detail.
|
441
443
|
</dd>
|
442
|
-
</dl>
|
443
|
-
<p>The followings are non-constraint entries.
|
444
|
-
</p>
|
445
|
-
<dl class="dl3">
|
446
444
|
<dt class="dt3"><strong>
|
447
445
|
<code>name:</code> </strong></dt>
|
448
446
|
<dd class="dd3">
|
@@ -454,46 +452,51 @@ document04b.yaml#0: INVALID
|
|
454
452
|
Description. This is not used for validation.
|
455
453
|
</dd>
|
456
454
|
<dt class="dt3"><strong>
|
457
|
-
<code>
|
455
|
+
<code>class:</code> </strong></dt>
|
456
|
+
<dd class="dd3">
|
457
|
+
Class name. This is for data-binding and is available only with type 'map'.
|
458
|
+
This is also used in 'genclass' action.
|
459
|
+
</dd>
|
460
|
+
<dt class="dt3"><strong>
|
461
|
+
<code>default:</code> </strong></dt>
|
458
462
|
<dd class="dd3">
|
459
|
-
|
463
|
+
Default value.
|
464
|
+
This is only for 'genclass' action, and have no effect to validation and parsing.
|
465
|
+
Default value should be scalar and it is not available if <code>type:</code> is <code>map</code> or <code>seq</code>, and also not available when <code>required:</code> is true.
|
460
466
|
</dd>
|
461
467
|
</dl>
|
462
|
-
<p>Rule contains 'type:' entry. 'sequence:' entry takes a list of rule. 'mapping:' entry takes a hash which values are rules.
|
463
|
-
</p>
|
464
468
|
<a name="schema05.yaml"></a>
|
465
469
|
<div class="program_caption">
|
466
470
|
<code>schema05.yaml</code> : rule examples</div>
|
467
|
-
<pre class="program">type: seq
|
471
|
+
<pre class="program">type: seq
|
468
472
|
sequence:
|
469
473
|
-
|
470
|
-
type: map
|
474
|
+
type: map
|
471
475
|
mapping:
|
472
|
-
|
473
|
-
type: str
|
476
|
+
"name":
|
477
|
+
type: str
|
474
478
|
required: yes
|
475
|
-
|
476
|
-
type: str
|
479
|
+
"email":
|
480
|
+
type: str
|
477
481
|
required: yes
|
478
482
|
pattern: /@/
|
479
|
-
|
480
|
-
type: text
|
483
|
+
"password":
|
484
|
+
type: text
|
481
485
|
length: { max: 16, min: 8 }
|
482
|
-
|
483
|
-
type: int
|
486
|
+
"age":
|
487
|
+
type: int
|
484
488
|
range: { max: 30, min: 18 }
|
485
489
|
# or assert: 18 <= val && val <= 30
|
486
|
-
|
487
|
-
type: str
|
488
|
-
enum:
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
type:
|
495
|
-
|
496
|
-
type: any # new rule
|
490
|
+
"blood":
|
491
|
+
type: str
|
492
|
+
enum: [A, B, O, AB]
|
493
|
+
"birth":
|
494
|
+
type: date
|
495
|
+
"memo":
|
496
|
+
type: any
|
497
|
+
"deleted":
|
498
|
+
type: bool
|
499
|
+
default: false
|
497
500
|
</pre>
|
498
501
|
<a name="document05a.yaml"></a>
|
499
502
|
<div class="program_caption">
|
@@ -510,7 +513,7 @@ sequence:
|
|
510
513
|
blood: AB
|
511
514
|
birth: 1980-01-01
|
512
515
|
</pre>
|
513
|
-
<a name="valid05.
|
516
|
+
<a name="valid05.result"></a>
|
514
517
|
<div class="terminal_caption">
|
515
518
|
validate</div>
|
516
519
|
<pre class="terminal">$ kwalify -lf schema05.yaml document05a.yaml
|
@@ -532,7 +535,7 @@ document05a.yaml#0: valid.
|
|
532
535
|
blood: AB
|
533
536
|
birth: 1980/01/01
|
534
537
|
</pre>
|
535
|
-
<a name="invalid05.
|
538
|
+
<a name="invalid05.result"></a>
|
536
539
|
<div class="terminal_caption">
|
537
540
|
validate</div>
|
538
541
|
<pre class="terminal">$ kwalify -lf schema05.yaml document05b.yaml
|
@@ -541,8 +544,8 @@ document05b.yaml#0: INVALID
|
|
541
544
|
- (line 3) [/0/password] 'xxx123': too short (length 6 < min 8).
|
542
545
|
- (line 4) [/0/age] 'twenty': not a integer.
|
543
546
|
- (line 5) [/0/blood] 'a': invalid blood value.
|
544
|
-
- (line 7) [/1/given-name] key 'given-name:' is undefined.
|
545
547
|
- (line 7) [/1] key 'name:' is required.
|
548
|
+
- (line 7) [/1/given-name] key 'given-name:' is undefined.
|
546
549
|
- (line 8) [/1/family-name] key 'family-name:' is undefined.
|
547
550
|
- (line 10) [/1/age] '15': too small (< min 18).
|
548
551
|
- (line 12) [/1/birth] '1980/01/01': not a date.
|
@@ -552,12 +555,15 @@ document05b.yaml#0: INVALID
|
|
552
555
|
|
553
556
|
<a name="schema-unique"></a>
|
554
557
|
<h3 class="section2">Unique constraint</h3>
|
555
|
-
<p>'<code>unique:</code>' constraint
|
556
|
-
This is equivalent to unique
|
557
|
-
</p>
|
558
|
-
<p>Type of rule which has '<code>unique:</code>' entry must be scalar (str, int, float, ...).
|
559
|
-
Type of parent rule must be sequence or mapping.
|
558
|
+
<p>'<code>unique:</code>' constraint is available with elements of sequence or mapping.
|
559
|
+
This is equivalent to unique constraint of RDBMS.
|
560
560
|
</p>
|
561
|
+
<ul type="disc">
|
562
|
+
<li>Type of rule which has '<code>unique:</code>' entry must be scalar (str, int, float, ...).
|
563
|
+
</li>
|
564
|
+
<li>Type of parent rule must be sequence or mapping.
|
565
|
+
</li>
|
566
|
+
</ul>
|
561
567
|
<a name="schema06.yaml"></a>
|
562
568
|
<div class="program_caption">
|
563
569
|
<code>schema06.yaml</code> : unique constraint entry with mapping and sequence</div>
|
@@ -566,17 +572,12 @@ sequence:
|
|
566
572
|
- type: map
|
567
573
|
required: yes
|
568
574
|
mapping:
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
<strong>unique: yes</strong>
|
573
|
-
email:
|
574
|
-
type: str
|
575
|
-
groups:
|
575
|
+
"name": { type: str, required: yes, <strong>unique: yes</strong> }
|
576
|
+
"email": { type: str }
|
577
|
+
"groups":
|
576
578
|
type: seq
|
577
579
|
sequence:
|
578
|
-
- type: str
|
579
|
-
<strong>unique: yes</strong>
|
580
|
+
- { type: str, <strong>unique: yes</strong> }
|
580
581
|
</pre>
|
581
582
|
<a name="document06a.yaml"></a>
|
582
583
|
<div class="program_caption">
|
@@ -597,7 +598,7 @@ sequence:
|
|
597
598
|
groups:
|
598
599
|
- users
|
599
600
|
</pre>
|
600
|
-
<a name="valid06.
|
601
|
+
<a name="valid06.result"></a>
|
601
602
|
<div class="terminal_caption">
|
602
603
|
validate</div>
|
603
604
|
<pre class="terminal">$ kwalify -lf schema06.yaml document06a.yaml
|
@@ -623,7 +624,7 @@ document06a.yaml#0: valid.
|
|
623
624
|
groups:
|
624
625
|
- users
|
625
626
|
</pre>
|
626
|
-
<a name="invalid06.
|
627
|
+
<a name="invalid06.result"></a>
|
627
628
|
<div class="terminal_caption">
|
628
629
|
validate</div>
|
629
630
|
<pre class="terminal">$ kwalify -lf schema06.yaml document06b.yaml
|
@@ -634,364 +635,19 @@ document06b.yaml#0: INVALID
|
|
634
635
|
<br>
|
635
636
|
|
636
637
|
|
637
|
-
<a name="schema-hook"></a>
|
638
|
-
<h3 class="section2">Validator#validator_hook()</h3>
|
639
|
-
<p>You can extend Kwalify::Validator class (Ruby) or kwalify.Validator class (Java), and override Kwalify::Validator#validator_hook() method (Ruby) or kwalify.Validator#validateHook() method (Java).
|
640
|
-
This method is called by Kwalify::Validator#validate() (Ruby) or kwalify.Validator#validate() (Java).
|
641
|
-
</p>
|
642
|
-
<a name="answers-schema.yaml"></a>
|
643
|
-
<div class="program_caption">
|
644
|
-
answers-schema.yaml : 'name:' is important.</div>
|
645
|
-
<pre class="program">type: map
|
646
|
-
mapping:
|
647
|
-
answers:
|
648
|
-
type: seq
|
649
|
-
sequence:
|
650
|
-
- type: map
|
651
|
-
<strong>name: Answer</strong>
|
652
|
-
mapping:
|
653
|
-
name:
|
654
|
-
type: str
|
655
|
-
required: yes
|
656
|
-
answer:
|
657
|
-
type: str
|
658
|
-
required: yes
|
659
|
-
enum:
|
660
|
-
- good
|
661
|
-
- not bad
|
662
|
-
- bad
|
663
|
-
reason:
|
664
|
-
type: str
|
665
|
-
</pre>
|
666
|
-
<a name="answers-validator.rb"></a>
|
667
|
-
<div class="program_caption">
|
668
|
-
answers-validator.rb : validate script for Ruby</div>
|
669
|
-
<pre class="program">#!/usr/bin/env ruby
|
670
|
-
|
671
|
-
require 'kwalify'
|
672
|
-
require 'yaml'
|
673
|
-
|
674
|
-
## validator class for answers
|
675
|
-
class AnswersValidator < Kwalify::Validator
|
676
|
-
|
677
|
-
## load schema definition
|
678
|
-
@@schema = YAML.load_file('answers-schema.yaml')
|
679
|
-
|
680
|
-
def initialize()
|
681
|
-
super(@@schema)
|
682
|
-
end
|
683
|
-
|
684
|
-
## hook method called by Validator#validate()
|
685
|
-
<strong>def validate_hook(value, rule, path, errors)</strong>
|
686
|
-
<strong>case rule.name</strong>
|
687
|
-
<strong>when 'Answer'</strong>
|
688
|
-
if value['answer'] == 'bad'
|
689
|
-
reason = value['reason']
|
690
|
-
if !reason || reason.empty?
|
691
|
-
msg = "reason is required when answer is 'bad'."
|
692
|
-
errors << Kwalify::ValidationError.new(msg, path)
|
693
|
-
end
|
694
|
-
end
|
695
|
-
end
|
696
|
-
end
|
697
|
-
|
698
|
-
end
|
699
|
-
|
700
|
-
## create validator
|
701
|
-
validator = AnswersValidator.new
|
702
|
-
|
703
|
-
## load YAML document
|
704
|
-
input = ARGF.read()
|
705
|
-
document = YAML.load(input)
|
706
|
-
|
707
|
-
## validate
|
708
|
-
errors = validator.validate(document)
|
709
|
-
if errors.empty?
|
710
|
-
puts "Valid."
|
711
|
-
else
|
712
|
-
puts "*** INVALID!"
|
713
|
-
errors.each do |error|
|
714
|
-
# error.class == Kwalify::ValidationError
|
715
|
-
puts " - [#{error.path}] : #{error.message}"
|
716
|
-
end
|
717
|
-
end
|
718
|
-
</pre>
|
719
|
-
<a name="document07a.yaml"></a>
|
720
|
-
<div class="program_caption">
|
721
|
-
<code>document07a.yaml</code> : valid document example</div>
|
722
|
-
<pre class="program">answers:
|
723
|
-
- name: Foo
|
724
|
-
answer: good
|
725
|
-
reason: I like this style.
|
726
|
-
- name: Bar
|
727
|
-
answer: not bad
|
728
|
-
- name: Baz
|
729
|
-
answer: bad
|
730
|
-
reason: I don't like this style.
|
731
|
-
</pre>
|
732
|
-
<a name="valid07.expected"></a>
|
733
|
-
<div class="terminal_caption">
|
734
|
-
validate</div>
|
735
|
-
<pre class="terminal">$ ruby answers-validator.rb document07a.yaml
|
736
|
-
Valid.
|
737
|
-
</pre>
|
738
|
-
<a name="document07b.yaml"></a>
|
739
|
-
<div class="program_caption">
|
740
|
-
<code>document07b.yaml</code> : invalid document example</div>
|
741
|
-
<pre class="program">answers:
|
742
|
-
- name: Foo
|
743
|
-
answer: good
|
744
|
-
- name: Bar
|
745
|
-
answer: bad
|
746
|
-
- name: Baz
|
747
|
-
answer: not bad
|
748
|
-
</pre>
|
749
|
-
<a name="invalid07.expected"></a>
|
750
|
-
<div class="terminal_caption">
|
751
|
-
validate</div>
|
752
|
-
<pre class="terminal">$ ruby answers-validator.rb document07b.yaml
|
753
|
-
*** INVALID!
|
754
|
-
- [/answers/1] : reason is required when answer is 'bad'.
|
755
|
-
</pre>
|
756
|
-
<p>You can validate some document by a Validator instance because Validator class and Validator#validate() method are stateless. If you use instance variables in custom validator_hook() method, it becomes to be stateful.
|
757
|
-
</p>
|
758
|
-
<p>Here is a Java program equivarent to 'answers-validator.rb'.
|
759
|
-
</p>
|
760
|
-
<a name="AnswersValidator.java"></a>
|
761
|
-
<div class="program_caption">
|
762
|
-
AnswersValidator.java : validate program for Java</div>
|
763
|
-
<pre class="program">import kwalify.Validator;
|
764
|
-
import kwalify.Rule;
|
765
|
-
import kwalify.Util;
|
766
|
-
import kwalify.YamlUtil;
|
767
|
-
import kwalify.YamlParser;
|
768
|
-
import kwalify.SyntaxException;
|
769
|
-
import kwalify.ValidationException;
|
770
|
-
|
771
|
-
import java.util.*;
|
772
|
-
import java.io.IOException;
|
773
|
-
|
774
|
-
|
775
|
-
/**
|
776
|
-
* validator class for answers
|
777
|
-
*/
|
778
|
-
public class AnswersValidator extends Validator {
|
779
|
-
|
780
|
-
/** schema string */
|
781
|
-
private static final String SCHEMA = ""
|
782
|
-
+ "type: map\n"
|
783
|
-
+ "mapping:\n"
|
784
|
-
+ " answers:\n"
|
785
|
-
+ " type: seq\n"
|
786
|
-
+ " sequence:\n"
|
787
|
-
+ " - type: map\n"
|
788
|
-
+ " name: Answer\n"
|
789
|
-
+ " mapping:\n"
|
790
|
-
+ " name:\n"
|
791
|
-
+ " type: str\n"
|
792
|
-
+ " required: yes\n"
|
793
|
-
+ " answer:\n"
|
794
|
-
+ " type: str\n"
|
795
|
-
+ " required: yes\n"
|
796
|
-
+ " enum:\n"
|
797
|
-
+ " - good\n"
|
798
|
-
+ " - not bad\n"
|
799
|
-
+ " - bad\n"
|
800
|
-
+ " reason:\n"
|
801
|
-
+ " type: str\n"
|
802
|
-
;
|
803
|
-
|
804
|
-
/** schema object */
|
805
|
-
private static Map schema = null;
|
806
|
-
static {
|
807
|
-
try {
|
808
|
-
schema = (Map)YamlUtil.load(SCHEMA);
|
809
|
-
} catch (SyntaxException ex) {
|
810
|
-
assert false;
|
811
|
-
}
|
812
|
-
}
|
813
|
-
|
814
|
-
/** construnctor */
|
815
|
-
public AnswersValidator() {
|
816
|
-
super(schema);
|
817
|
-
}
|
818
|
-
|
819
|
-
/** hook method called by Validator#validate() */
|
820
|
-
protected void validateHook(Object value, Rule rule, String path, List errors) {
|
821
|
-
String rule_name = rule.getName();
|
822
|
-
if (rule_name != null && rule_name.equals("Answer")) {
|
823
|
-
assert value instanceof Map;
|
824
|
-
Map val = (Map)value;
|
825
|
-
assert val.get("answer") != null;
|
826
|
-
if (val.get("answer").equals("bad")) {
|
827
|
-
String reason = (String)val.get("reason");
|
828
|
-
if (reason == null || reason.length() == 0) {
|
829
|
-
String msg = "reason is required when answer is 'bad'.";
|
830
|
-
errors.add(new ValidationException(msg, path));
|
831
|
-
}
|
832
|
-
}
|
833
|
-
}
|
834
|
-
}
|
835
|
-
|
836
|
-
/** main program */
|
837
|
-
public static void main(String[] args) throws IOException, SyntaxException {
|
838
|
-
// create validator
|
839
|
-
Validator validator = new AnswersValidator();
|
840
|
-
|
841
|
-
// load YAML document
|
842
|
-
String input;
|
843
|
-
if (args.length > 0) {
|
844
|
-
input = Util.readFile(args[0]);
|
845
|
-
} else {
|
846
|
-
input = Util.readInputStream(System.in);
|
847
|
-
}
|
848
|
-
YamlParser parser = new YamlParser(input);
|
849
|
-
Object document = parser.parse();
|
850
|
-
|
851
|
-
// validate and show errors
|
852
|
-
List errors = validator.validate(document);
|
853
|
-
if (errors == null || errors.size() == 0) {
|
854
|
-
System.out.println("Valid.");
|
855
|
-
} else {
|
856
|
-
System.out.println("*** INVALID!");
|
857
|
-
parser.setErrorsLineNumber(errors);
|
858
|
-
Collections.sort(errors);
|
859
|
-
for (Iterator it = errors.iterator(); it.hasNext(); ) {
|
860
|
-
ValidationException error = (ValidationException)it.next();
|
861
|
-
int linenum = error.getLineNumber();
|
862
|
-
String path = error.getPath();
|
863
|
-
String mesg = error.getMessage();
|
864
|
-
String s = "- line " + linenum + ": [" + path + "] " + mesg;
|
865
|
-
System.out.println(s);
|
866
|
-
}
|
867
|
-
}
|
868
|
-
}
|
869
|
-
}
|
870
|
-
</pre>
|
871
|
-
<a name="AnswersValidator.expected"></a>
|
872
|
-
<div class="terminal_caption">
|
873
|
-
validate</div>
|
874
|
-
<pre class="terminal">$ java -classpath kwalify.jar AnswersValidator document07a.yaml
|
875
|
-
Valid.
|
876
|
-
$ java -classpath kwalify.jar AnswersValidator document07b.yaml
|
877
|
-
*** INVALID!
|
878
|
-
- line 4: [/answers/1] reason is required when answer is 'bad'.
|
879
|
-
</pre>
|
880
|
-
<br>
|
881
|
-
|
882
|
-
|
883
|
-
<a name="schema-block"></a>
|
884
|
-
<h3 class="section2">Validator with Block</h3>
|
885
|
-
<p><strong>Notice: This feature has been obsolete. Use Kwalify::Validator#validate_hook() method instead.</strong>
|
886
|
-
</p>
|
887
|
-
<p><code>Kwalify::Validator.new()</code> method can take a block which is invoked when validation.
|
888
|
-
</p>
|
889
|
-
<a name="validate08.rb"></a>
|
890
|
-
<div class="program_caption">
|
891
|
-
<code>validate08.rb</code> : validate script</div>
|
892
|
-
<pre class="program">#!/usr/bin/env ruby
|
893
|
-
|
894
|
-
require 'kwalify'
|
895
|
-
require 'yaml'
|
896
|
-
|
897
|
-
## load schema definition
|
898
|
-
schema = YAML.load_file('answers-schema.yaml')
|
899
|
-
|
900
|
-
## create validator for answers
|
901
|
-
validator = Kwalify::Validator.new(schema) <strong>{ |value, rule, path, errors|</strong>
|
902
|
-
<strong>case rule.name</strong>
|
903
|
-
<strong>when 'Answer'</strong>
|
904
|
-
if value['answer'] == 'bad'
|
905
|
-
reason = value['reason']
|
906
|
-
if !reason || reason.empty?
|
907
|
-
msg = "reason is required when answer is 'bad'."
|
908
|
-
errors << Kwalify::ValidationError.new(msg, path)
|
909
|
-
end
|
910
|
-
end
|
911
|
-
end
|
912
|
-
<strong>}</strong>
|
913
|
-
|
914
|
-
## load YAML document
|
915
|
-
input = ARGF.read()
|
916
|
-
document = YAML.load(input)
|
917
|
-
|
918
|
-
## validate
|
919
|
-
errors = validator.validate(document)
|
920
|
-
if errors.empty?
|
921
|
-
puts "Valid."
|
922
|
-
else
|
923
|
-
puts "*** INVALID!"
|
924
|
-
errors.each do |error|
|
925
|
-
# error.class == Kwalify::ValidationError
|
926
|
-
puts " - [#{error.path}] : #{error.message}"
|
927
|
-
end
|
928
|
-
end
|
929
|
-
</pre>
|
930
|
-
<a name="valid08.expected"></a>
|
931
|
-
<div class="terminal_caption">
|
932
|
-
validate</div>
|
933
|
-
<pre class="terminal">$ ruby validate08.rb document07a.yaml
|
934
|
-
Valid.
|
935
|
-
</pre>
|
936
|
-
<a name="valid08.expected"></a>
|
937
|
-
<div class="terminal_caption">
|
938
|
-
validate</div>
|
939
|
-
<pre class="terminal">$ ruby validate08.rb document07b.yaml
|
940
|
-
*** INVALID!
|
941
|
-
- [/answers/1] : reason is required when answer is 'bad'.
|
942
|
-
</pre>
|
943
|
-
<br>
|
944
|
-
|
945
|
-
|
946
638
|
<br>
|
947
639
|
|
948
640
|
|
949
641
|
<a name="tips"></a>
|
950
642
|
<h2 class="section1">Tips</h2>
|
951
|
-
<a name="tips-quotes"></a>
|
952
|
-
<h3 class="section2">Enclose Key Names in (Double) Quotes</h3>
|
953
|
-
<p>It is allowed to enclose key name in quotes (') or double-quotes (") in YAML.
|
954
|
-
This tip highlights user-defined key names.
|
955
|
-
</p>
|
956
|
-
<div class="program_caption">
|
957
|
-
<code>schema11a.yaml</code> : enclosing in double-quotes</div>
|
958
|
-
<pre class="program">type: map
|
959
|
-
mapping:
|
960
|
-
"name":
|
961
|
-
required: yes
|
962
|
-
"email":
|
963
|
-
pattern: /@/
|
964
|
-
"age":
|
965
|
-
type: int
|
966
|
-
"birth":
|
967
|
-
type: date
|
968
|
-
</pre>
|
969
|
-
<p>You may prefer to indent with 1 space and 3 spaces.
|
970
|
-
</p>
|
971
|
-
<div class="program_caption">
|
972
|
-
<code>schema11b.yaml</code> : indent with 1 space and 3 spaces</div>
|
973
|
-
<pre class="program">type: map
|
974
|
-
mapping:
|
975
|
-
"name":
|
976
|
-
required: yes
|
977
|
-
"email":
|
978
|
-
pattern: /@/
|
979
|
-
"age":
|
980
|
-
type: int
|
981
|
-
"birth":
|
982
|
-
type: date
|
983
|
-
</pre>
|
984
|
-
<br>
|
985
|
-
|
986
|
-
|
987
643
|
<a name="tips-json"></a>
|
988
644
|
<h3 class="section2">JSON</h3>
|
989
645
|
<p><a href="http://www.json.org">JSON</a> is a lightweight data-interchange format, especially useful for JavaScript.
|
990
646
|
JSON can be considered as a subset of YAML. It means that YAML parser can parse JSON and Kwalify can validate JSON document.
|
991
647
|
</p>
|
992
|
-
<a name="schema12.
|
648
|
+
<a name="schema12.json"></a>
|
993
649
|
<div class="program_caption">
|
994
|
-
<code>schema12.
|
650
|
+
<code>schema12.json</code> : an example schema definition written in JSON format</div>
|
995
651
|
<pre class="program">{ "type": "map",
|
996
652
|
"required": true,
|
997
653
|
"mapping": {
|
@@ -1000,16 +656,14 @@ JSON can be considered as a subset of YAML. It means that YAML parser can parse
|
|
1000
656
|
"age": { "type": "int" },
|
1001
657
|
"gender": { "type": "str", "enum": ["M", "F"] },
|
1002
658
|
"favorite": { "type": "seq",
|
1003
|
-
"sequence": [
|
1004
|
-
|
1005
|
-
]
|
1006
|
-
}
|
659
|
+
"sequence": [ { "type": "str" } ]
|
660
|
+
}
|
1007
661
|
}
|
1008
662
|
}
|
1009
663
|
</pre>
|
1010
|
-
<a name="document12a.
|
664
|
+
<a name="document12a.json"></a>
|
1011
665
|
<div class="program_caption">
|
1012
|
-
<code>document12a.
|
666
|
+
<code>document12a.json</code> : valid JSON document example</div>
|
1013
667
|
<pre class="program">{ "name": "Foo",
|
1014
668
|
"email": "foo@mail.com",
|
1015
669
|
"age": 20,
|
@@ -1021,15 +675,15 @@ JSON can be considered as a subset of YAML. It means that YAML parser can parse
|
|
1021
675
|
]
|
1022
676
|
}
|
1023
677
|
</pre>
|
1024
|
-
<a name="valid12.
|
678
|
+
<a name="valid12.result"></a>
|
1025
679
|
<div class="terminal_caption">
|
1026
680
|
validate</div>
|
1027
|
-
<pre class="terminal">$ kwalify -lf schema12.
|
1028
|
-
document12a.
|
681
|
+
<pre class="terminal">$ kwalify -lf schema12.json document12a.json
|
682
|
+
document12a.json#0: valid.
|
1029
683
|
</pre>
|
1030
|
-
<a name="document12b.
|
684
|
+
<a name="document12b.json"></a>
|
1031
685
|
<div class="program_caption">
|
1032
|
-
<code>document12b.
|
686
|
+
<code>document12b.json</code> : invalid JSON document example</div>
|
1033
687
|
<pre class="program">{
|
1034
688
|
"mail": "foo@mail.com",
|
1035
689
|
"age": twenty,
|
@@ -1037,11 +691,11 @@ document12a.yaml#0: valid.
|
|
1037
691
|
"favorite": [ 123, 456 ]
|
1038
692
|
}
|
1039
693
|
</pre>
|
1040
|
-
<a name="invalid12.
|
694
|
+
<a name="invalid12.json"></a>
|
1041
695
|
<div class="terminal_caption">
|
1042
696
|
validate</div>
|
1043
|
-
<pre class="terminal">$ kwalify -lf schema12.
|
1044
|
-
document12b.
|
697
|
+
<pre class="terminal">$ kwalify -lf schema12.json document12b.json
|
698
|
+
document12b.json#0: INVALID
|
1045
699
|
- (line 1) [/] key 'name:' is required.
|
1046
700
|
- (line 2) [/mail] key 'mail:' is undefined.
|
1047
701
|
- (line 3) [/age] 'twenty': not a integer.
|
@@ -1053,8 +707,8 @@ document12b.yaml#0: INVALID
|
|
1053
707
|
|
1054
708
|
|
1055
709
|
<a name="tips-anchor"></a>
|
1056
|
-
<h3 class="section2">Anchor</h3>
|
1057
|
-
<p>You can share
|
710
|
+
<h3 class="section2">Anchor and Alias</h3>
|
711
|
+
<p>You can share rules by YAML anchor and alias.
|
1058
712
|
</p>
|
1059
713
|
<a name="schema13.yaml"></a>
|
1060
714
|
<div class="program_caption">
|
@@ -1069,13 +723,11 @@ sequence:
|
|
1069
723
|
required: yes
|
1070
724
|
"family-name": <strong>*name</strong>
|
1071
725
|
"post":
|
1072
|
-
|
1073
|
-
|
1074
|
-
- manager
|
1075
|
-
- clerk
|
726
|
+
type: str
|
727
|
+
enum: [exective, manager, clerk]
|
1076
728
|
"supervisor": <strong>*employee</strong>
|
1077
729
|
</pre>
|
1078
|
-
<p>Anchor is also available in YAML document.
|
730
|
+
<p>Anchor and alias is also available in YAML document.
|
1079
731
|
</p>
|
1080
732
|
<a name="document13a.yaml"></a>
|
1081
733
|
<div class="program_caption">
|
@@ -1098,7 +750,7 @@ sequence:
|
|
1098
750
|
post: clerk
|
1099
751
|
supervisor: <strong>*bar</strong>
|
1100
752
|
</pre>
|
1101
|
-
<a name="valid13.
|
753
|
+
<a name="valid13.result"></a>
|
1102
754
|
<div class="terminal_caption">
|
1103
755
|
validate</div>
|
1104
756
|
<pre class="terminal">$ kwalify -lf schema13.yaml document13a.yaml
|
@@ -1142,7 +794,7 @@ mapping:
|
|
1142
794
|
value2: 0.5
|
1143
795
|
value3: -0.9
|
1144
796
|
</pre>
|
1145
|
-
<a name="valid14.
|
797
|
+
<a name="valid14.result"></a>
|
1146
798
|
<div class="terminal_caption">
|
1147
799
|
validate</div>
|
1148
800
|
<pre class="terminal">$ kwalify -lf schema14.yaml document14a.yaml
|
@@ -1155,7 +807,7 @@ document14a.yaml#0: valid.
|
|
1155
807
|
value2: 1.1
|
1156
808
|
value3: -2.0
|
1157
809
|
</pre>
|
1158
|
-
<a name="invalid14.
|
810
|
+
<a name="invalid14.result"></a>
|
1159
811
|
<div class="terminal_caption">
|
1160
812
|
validate</div>
|
1161
813
|
<pre class="terminal">$ kwalify -lf schema14.yaml document14b.yaml
|
@@ -1207,10 +859,10 @@ mapping:
|
|
1207
859
|
mapping:
|
1208
860
|
"name":
|
1209
861
|
<strong><<: *name</strong> # merge
|
1210
|
-
<strong>length: { max: 16 }</strong> #
|
862
|
+
<strong>length: { max: 16 }</strong> # add
|
1211
863
|
"email":
|
1212
864
|
<strong><<: *email</strong> # merge
|
1213
|
-
<strong>required: yes</strong> #
|
865
|
+
<strong>required: yes</strong> # override
|
1214
866
|
</pre>
|
1215
867
|
<a name="document15a.yaml"></a>
|
1216
868
|
<div class="program_caption">
|
@@ -1222,7 +874,7 @@ user:
|
|
1222
874
|
name: bar
|
1223
875
|
email: bar@mail.com
|
1224
876
|
</pre>
|
1225
|
-
<a name="valid15.
|
877
|
+
<a name="valid15.result"></a>
|
1226
878
|
<div class="terminal_caption">
|
1227
879
|
validate</div>
|
1228
880
|
<pre class="terminal">$ kwalify -lf schema15.yaml document15a.yaml
|
@@ -1237,12 +889,12 @@ document15a.yaml#0: valid.
|
|
1237
889
|
user:
|
1238
890
|
name: toooooo-looooong-name
|
1239
891
|
</pre>
|
1240
|
-
<a name="invalid15.
|
892
|
+
<a name="invalid15.result"></a>
|
1241
893
|
<div class="terminal_caption">
|
1242
894
|
validate</div>
|
1243
895
|
<pre class="terminal">$ kwalify -lf schema15.yaml document15b.yaml
|
1244
896
|
document15b.yaml#0: INVALID
|
1245
|
-
- (line
|
897
|
+
- (line 5) [/user] key 'email:' is required.
|
1246
898
|
- (line 5) [/user/name] 'toooooo-looooong-name': too long (length 21 > max 16).
|
1247
899
|
</pre>
|
1248
900
|
<br>
|
@@ -1251,21 +903,602 @@ document15b.yaml#0: INVALID
|
|
1251
903
|
<br>
|
1252
904
|
|
1253
905
|
|
1254
|
-
<a name="
|
1255
|
-
<h2 class="section1">
|
1256
|
-
<p>
|
1257
|
-
|
906
|
+
<a name="howto"></a>
|
907
|
+
<h2 class="section1">How to in Ruby</h2>
|
908
|
+
<p>This section describes how to use Kwalify in Ruby.
|
909
|
+
</p>
|
910
|
+
<a name="howot-validate"></a>
|
911
|
+
<h3 class="section2">Validation</h3>
|
912
|
+
<a name="howto-validation.rb"></a>
|
913
|
+
<pre class="program">require 'kwalify'
|
914
|
+
#require 'yaml'
|
915
|
+
|
916
|
+
## load schema data
|
917
|
+
schema = Kwalify::Yaml.load_file('schema.yaml')
|
918
|
+
## or
|
919
|
+
#schema = YAML.load_file('schema.yaml')
|
920
|
+
|
921
|
+
## create validator
|
922
|
+
validator = Kwalify::Validator.new(schema)
|
923
|
+
|
924
|
+
## load document
|
925
|
+
document = Kwalify::Yaml.load_file('document.yaml')
|
926
|
+
## or
|
927
|
+
#document = YAML.load_file('document.yaml')
|
928
|
+
|
929
|
+
## validate
|
930
|
+
errors = validator.validate(document)
|
931
|
+
|
932
|
+
## show errors
|
933
|
+
if errors && !errors.empty?
|
934
|
+
for err in errors
|
935
|
+
puts "[#{err.path}] #{err.message}"
|
936
|
+
end
|
937
|
+
end
|
938
|
+
</pre>
|
939
|
+
<br>
|
940
|
+
|
941
|
+
|
942
|
+
<a name="howto-parse"></a>
|
943
|
+
<h3 class="section2">Parsing with Validation</h3>
|
944
|
+
<p>From version 0.7, Kwalify supports parsing with validation.
|
945
|
+
</p>
|
946
|
+
<a name="howto-validation-with-parsing.rb"></a>
|
947
|
+
<pre class="program">require 'kwalify'
|
948
|
+
#require 'yaml'
|
949
|
+
|
950
|
+
## load schema data
|
951
|
+
schema = Kwalify::Yaml.load_file('schema.yaml')
|
952
|
+
## or
|
953
|
+
#schema = YAML.load_file('schema.yaml')
|
954
|
+
|
955
|
+
## create validator
|
956
|
+
validator = Kwalify::Validator.new(schema)
|
957
|
+
|
958
|
+
## create parser with validator
|
959
|
+
## (if validator is ommitted, no validation executed.)
|
960
|
+
parser = Kwalify:::Yaml::Parser.new(validator)
|
961
|
+
|
962
|
+
## parse document with validation
|
963
|
+
filename = 'document.yaml'
|
964
|
+
document = parser.parse_file(filename)
|
965
|
+
## or
|
966
|
+
#document = parser.parse(File.read(filename), filename)
|
967
|
+
|
968
|
+
## show errors if exist
|
969
|
+
errors = parser.errors()
|
970
|
+
if errors && !errors.empty?
|
971
|
+
for e in errors
|
972
|
+
puts "#{e.linenum}:#{e.column} [#{e.path}] #{e.message}"
|
973
|
+
end
|
974
|
+
end
|
975
|
+
</pre>
|
976
|
+
<br>
|
977
|
+
|
978
|
+
|
979
|
+
<a name="howto-meta"></a>
|
980
|
+
<h3 class="section2">Meta Validation</h3>
|
981
|
+
<p>Meta validator is a validator which validates schema definition.
|
982
|
+
The schema definition is placed at 'kwalify/kwalify.schema.yaml'.
|
983
|
+
</p>
|
984
|
+
<p>Kwalify also provides Kwalify::MetaValidator class which validates
|
985
|
+
schema defition.
|
986
|
+
</p>
|
987
|
+
<pre class="program">require 'kwalify'
|
988
|
+
|
989
|
+
## meta validator
|
990
|
+
metavalidator = Kwalify::MetaValidator.instance
|
991
|
+
|
992
|
+
## validate schema definition
|
993
|
+
parser = Kwalify::Yaml::Parser.new(metavalidator)
|
994
|
+
errors = parser.parse_file('schema.yaml')
|
995
|
+
for e in errors
|
996
|
+
puts "#{e.linenum}:#{e.column} [#{e.path}] #{e.message}"
|
997
|
+
end if errors && !errors.empty?
|
998
|
+
</pre>
|
999
|
+
<p>Meta validation is also available with command-line option '-m'.
|
1000
|
+
</p>
|
1001
|
+
<pre class="terminal">$ kwalify -m schema1.yaml schema2.yaml ...
|
1002
|
+
</pre>
|
1003
|
+
<br>
|
1004
|
+
|
1005
|
+
|
1006
|
+
<a name="howto-hook"></a>
|
1007
|
+
<h3 class="section2">Validator#validator_hook()</h3>
|
1008
|
+
<p>You can extend Kwalify::Validator and override Kwalify::Validator#validator_hook() method.
|
1009
|
+
This method is called by Kwalify::Validator#validate().
|
1010
|
+
</p>
|
1011
|
+
<a name="answers-schema.yaml"></a>
|
1012
|
+
<div class="program_caption">
|
1013
|
+
answers-schema.yaml : 'name:' is important.</div>
|
1014
|
+
<pre class="program">type: map
|
1015
|
+
mapping:
|
1016
|
+
"answers":
|
1017
|
+
type: seq
|
1018
|
+
sequence:
|
1019
|
+
- type: map
|
1020
|
+
<strong>name: Answer</strong>
|
1021
|
+
mapping:
|
1022
|
+
"name": { type: str, required: yes }
|
1023
|
+
"answer": { type: str, required: yes,
|
1024
|
+
enum: [good, not bad, bad] }
|
1025
|
+
"reason": { type: str }
|
1026
|
+
</pre>
|
1027
|
+
<a name="answers-validator.rb"></a>
|
1028
|
+
<div class="program_caption">
|
1029
|
+
answers-validator.rb : validate script for Ruby</div>
|
1030
|
+
<pre class="program">#!/usr/bin/env ruby
|
1031
|
+
|
1032
|
+
require 'kwalify'
|
1033
|
+
|
1034
|
+
## validator class for answers
|
1035
|
+
class AnswersValidator < Kwalify::Validator
|
1036
|
+
|
1037
|
+
## load schema definition
|
1038
|
+
@@schema = Kwalify::Yaml.load_file('answers-schema.yaml')
|
1039
|
+
## or
|
1040
|
+
## require 'yaml'
|
1041
|
+
## @@schema = YAML.load_file('answers-schema.yaml')
|
1042
|
+
|
1043
|
+
def initialize()
|
1044
|
+
super(@@schema)
|
1045
|
+
end
|
1046
|
+
|
1047
|
+
## hook method called by Validator#validate()
|
1048
|
+
<strong>def validate_hook(value, rule, path, errors)</strong>
|
1049
|
+
<strong>case rule.name</strong>
|
1050
|
+
<strong>when 'Answer'</strong>
|
1051
|
+
if value['answer'] == 'bad'
|
1052
|
+
reason = value['reason']
|
1053
|
+
if !reason || reason.empty?
|
1054
|
+
msg = "reason is required when answer is 'bad'."
|
1055
|
+
errors << Kwalify::ValidationError.new(msg, path)
|
1056
|
+
end
|
1057
|
+
end
|
1058
|
+
end
|
1059
|
+
end
|
1060
|
+
|
1061
|
+
end
|
1062
|
+
|
1063
|
+
## create validator
|
1064
|
+
validator = AnswersValidator.new
|
1065
|
+
|
1066
|
+
## load YAML document
|
1067
|
+
input = ARGF.read()
|
1068
|
+
document = Kwalify::Yaml.load(input)
|
1069
|
+
## or document = YAML.load(input)
|
1070
|
+
|
1071
|
+
## validate
|
1072
|
+
errors = validator.validate(document)
|
1073
|
+
if errors.empty?
|
1074
|
+
puts "Valid."
|
1075
|
+
else
|
1076
|
+
puts "*** INVALID!"
|
1077
|
+
errors.each do |error|
|
1078
|
+
# error.class == Kwalify::ValidationError
|
1079
|
+
puts " - [#{error.path}] : #{error.message}"
|
1080
|
+
end
|
1081
|
+
end
|
1082
|
+
</pre>
|
1083
|
+
<a name="document07a.yaml"></a>
|
1084
|
+
<div class="program_caption">
|
1085
|
+
<code>document07a.yaml</code> : valid document example</div>
|
1086
|
+
<pre class="program">answers:
|
1087
|
+
- name: Foo
|
1088
|
+
answer: good
|
1089
|
+
reason: I like this style.
|
1090
|
+
- name: Bar
|
1091
|
+
answer: not bad
|
1092
|
+
- name: Baz
|
1093
|
+
answer: bad
|
1094
|
+
reason: I don't like this style.
|
1095
|
+
</pre>
|
1096
|
+
<a name="valid07.result"></a>
|
1097
|
+
<div class="terminal_caption">
|
1098
|
+
validate</div>
|
1099
|
+
<pre class="terminal">$ ruby answers-validator.rb document07a.yaml
|
1100
|
+
Valid.
|
1101
|
+
</pre>
|
1102
|
+
<a name="document07b.yaml"></a>
|
1103
|
+
<div class="program_caption">
|
1104
|
+
<code>document07b.yaml</code> : invalid document example</div>
|
1105
|
+
<pre class="program">answers:
|
1106
|
+
- name: Foo
|
1107
|
+
answer: good
|
1108
|
+
- name: Bar
|
1109
|
+
answer: bad
|
1110
|
+
- name: Baz
|
1111
|
+
answer: not bad
|
1112
|
+
</pre>
|
1113
|
+
<a name="invalid07.result"></a>
|
1114
|
+
<div class="terminal_caption">
|
1115
|
+
validate</div>
|
1116
|
+
<pre class="terminal">$ ruby answers-validator.rb document07b.yaml
|
1117
|
+
*** INVALID!
|
1118
|
+
- [/answers/1] : reason is required when answer is 'bad'.
|
1119
|
+
</pre>
|
1120
|
+
<p>You can validate some document by a Validator instance because Validator class and Validator#validate() method are stateless. If you use instance variables in custom validator_hook() method, it becomes to be stateful.
|
1121
|
+
</p>
|
1122
|
+
<br>
|
1123
|
+
|
1124
|
+
|
1125
|
+
<a name="howto-preceding"></a>
|
1126
|
+
<h3 class="section2">Preceding Alias</h3>
|
1127
|
+
<p>From version 0.7, Kwalify allows aliases to appear before corresponding anchors are now appeared.
|
1128
|
+
These aliases are called as 'preceding alias'.
|
1129
|
+
</p>
|
1130
|
+
<a name="howto3.yaml"></a>
|
1131
|
+
<div class="program_caption">
|
1132
|
+
howto3.yaml</div>
|
1133
|
+
<pre class="program">- name: Foo
|
1134
|
+
parent: *bar # preceding alias
|
1135
|
+
- &bar
|
1136
|
+
name: Bar
|
1137
|
+
parent: *baz # preceding alias
|
1138
|
+
- &baz
|
1139
|
+
name: Baz
|
1140
|
+
parent: null
|
1141
|
+
</pre>
|
1142
|
+
<p>To enable preceding alias, set Kwalify::Yaml::Parser#preceding_alias to true.
|
1143
|
+
</p>
|
1144
|
+
<a name="howto3.rb"></a>
|
1145
|
+
<div class="program_caption">
|
1146
|
+
howto3.rb</div>
|
1147
|
+
<pre class="program">require 'kwalify'
|
1148
|
+
parser = Kwalify::Yaml::Parser.new
|
1149
|
+
<strong>parser.preceding_alias = true</strong> # enable preceding alias
|
1150
|
+
ydoc = parser.parse_file('howto3.yaml')
|
1151
|
+
require 'pp'
|
1152
|
+
pp ydoc
|
1153
|
+
</pre>
|
1154
|
+
<a name="howto3.result"></a>
|
1155
|
+
<div class="terminal_caption">
|
1156
|
+
result</div>
|
1157
|
+
<pre class="terminal">$ ruby howto3.rb
|
1158
|
+
[{"name"=>"Foo",
|
1159
|
+
"parent"=>{"name"=>"Bar", "parent"=>{"name"=>"Baz", "parent"=>nil}}},
|
1160
|
+
{"name"=>"Bar", "parent"=>{"name"=>"Baz", "parent"=>nil}},
|
1161
|
+
{"name"=>"Baz", "parent"=>nil}]
|
1162
|
+
</pre>
|
1163
|
+
<p>Command-line option '-P' also enables preceding alias.
|
1164
|
+
</p>
|
1165
|
+
<p>Preceding alias is very useful when document is complex.
|
1166
|
+
</p>
|
1167
|
+
<br>
|
1168
|
+
|
1169
|
+
|
1170
|
+
<a name="howto-databinding"></a>
|
1171
|
+
<h3 class="section2">Data Binding</h3>
|
1172
|
+
<p>From version 0.7, Kwalify supports data binding.
|
1173
|
+
* To enable data binding, set Kwlaify::Yaml::Parser#data_binding to true.
|
1174
|
+
* It is required to specify class name in schema definition.
|
1175
|
+
(Notice that 'class:' constraint is avaialbe only with rule which type is 'map'.)
|
1176
|
+
* Also instance methods '[]', '[]=', and 'keys?' must be defined in the classes.
|
1177
|
+
(Including Kwalify::Util::HashLike modules is easy way to define them.)
|
1178
|
+
</p>
|
1179
|
+
<a name="config.schema.yaml"></a>
|
1180
|
+
<div class="program_caption">
|
1181
|
+
config.schema.yaml: schema definition file</div>
|
1182
|
+
<pre class="program">type: map
|
1183
|
+
<strong>class: Config</strong>
|
1184
|
+
mapping:
|
1185
|
+
"host": { type: str, required: true }
|
1186
|
+
"port": { type: int }
|
1187
|
+
"user": { type: str, required: true }
|
1188
|
+
"pass": { type: str, required: true }
|
1189
|
+
</pre>
|
1190
|
+
<a name="config.yaml"></a>
|
1191
|
+
<div class="program_caption">
|
1192
|
+
config.yaml: data file</div>
|
1193
|
+
<pre class="program">host: localhost
|
1194
|
+
port: 8080
|
1195
|
+
user: user1
|
1196
|
+
pass: password1
|
1197
|
+
</pre>
|
1198
|
+
<a name="loadconfig.rb"></a>
|
1199
|
+
<div class="program_caption">
|
1200
|
+
loadconfig.rb: ruby program</div>
|
1201
|
+
<pre class="program">## class definition
|
1202
|
+
require 'kwalify/util/hashlike'
|
1203
|
+
<strong>class Config</strong>
|
1204
|
+
<strong>include Kwalify::Util::HashLike</strong> # defines [], []=, and keys?
|
1205
|
+
attr_accessor :host, :posrt, :user, :pass
|
1206
|
+
<strong>end</strong>
|
1207
|
+
## create validator object
|
1208
|
+
require 'kwalify'
|
1209
|
+
schema = Kwalify::Yaml.load_file('config.schema.yaml')
|
1210
|
+
validator = Kwalify::Validator.new(schema)
|
1211
|
+
## parse configuration file with data binding
|
1212
|
+
parser = Kwalify::Yaml::Parser.new(validator)
|
1213
|
+
<strong>parser.data_binding = true</strong> # enable data binding
|
1214
|
+
config = parser.parse_file('config.yaml')
|
1215
|
+
p config
|
1216
|
+
</pre>
|
1217
|
+
<a name="loadconfig.result"></a>
|
1218
|
+
<div class="terminal_caption">
|
1219
|
+
result</div>
|
1220
|
+
<pre class="terminal">$ ruby loadconfig.rb
|
1221
|
+
#<Config:0x542590 @host="localhost", @pass="password1", @port=8080, @user="user1">
|
1222
|
+
</pre>
|
1223
|
+
<p>Data binding is available even when data is more complex.
|
1224
|
+
Preceding alias is also available.
|
1225
|
+
</p>
|
1226
|
+
<p>For example, the following data is complex because it uses anchor and alias (including preceding alias).
|
1227
|
+
</p>
|
1228
|
+
<a name="BABEL.data.yaml"></a>
|
1229
|
+
<div class="program_caption">
|
1230
|
+
BABEL.data.yaml</div>
|
1231
|
+
<pre class="program">teams:
|
1232
|
+
- &thechildren
|
1233
|
+
name: The Children
|
1234
|
+
desc: Level 7 ESPers
|
1235
|
+
chief: *minamoto # preceding alias
|
1236
|
+
members: [*kaoru, *aoi, *shiho] # preceding aliases
|
1237
|
+
|
1238
|
+
members:
|
1239
|
+
- &minamoto
|
1240
|
+
name: Kohichi Minamoto
|
1241
|
+
desc: Scientist
|
1242
|
+
team: *thechildren
|
1243
|
+
- &kaoru
|
1244
|
+
name: Kaoru Akashi
|
1245
|
+
desc: Psychokino
|
1246
|
+
team: *thechildren
|
1247
|
+
- &aoi
|
1248
|
+
name: Aoi Nogami
|
1249
|
+
desc: Teleporter
|
1250
|
+
team: *thechildren
|
1251
|
+
- &shiho
|
1252
|
+
name: Shiho Sannomiya
|
1253
|
+
desc: Psycometrer
|
1254
|
+
team: *thechildren
|
1255
|
+
</pre>
|
1256
|
+
<p>Here is the schema definition.
|
1257
|
+
(Notice that 'class:' constraint is avaialbe only with rule which type is 'map'.)
|
1258
|
+
</p>
|
1259
|
+
<a name="BABEL.schema.yaml"></a>
|
1260
|
+
<div class="program_caption">
|
1261
|
+
BABEL.schema.yaml</div>
|
1262
|
+
<pre class="program">type: map
|
1263
|
+
required: yes
|
1264
|
+
mapping:
|
1265
|
+
"teams":
|
1266
|
+
type: seq
|
1267
|
+
required: yes
|
1268
|
+
sequence:
|
1269
|
+
- &team
|
1270
|
+
type: map
|
1271
|
+
required: yes
|
1272
|
+
<strong>class: Team</strong>
|
1273
|
+
mapping:
|
1274
|
+
"name": {type: str, required: yes, unique: yes}
|
1275
|
+
"desc": {type: str}
|
1276
|
+
"chief": *member # preceding alias
|
1277
|
+
"members":
|
1278
|
+
type: seq
|
1279
|
+
sequence: [*member] # preceding alias
|
1280
|
+
"members":
|
1281
|
+
type: seq
|
1282
|
+
required: yes
|
1283
|
+
sequence:
|
1284
|
+
- &member
|
1285
|
+
type: map
|
1286
|
+
required: yes
|
1287
|
+
<strong>class: Member</strong>
|
1288
|
+
mapping:
|
1289
|
+
"name": {type: str, required: yes, unique: yes}
|
1290
|
+
"desc": {type: str}
|
1291
|
+
"team": *team
|
1292
|
+
</pre>
|
1293
|
+
<p>It is required to define class 'Team' and 'Member' for data-binding.
|
1294
|
+
Command-line option '-a genclass-ruby' will help you to generate class definitions from schema definition.
|
1295
|
+
Try 'kwalify -ha genclass-ruby' for more details about 'genclass-ruby' action.
|
1296
|
+
</p>
|
1297
|
+
<a name="babel_genclass.result"></a>
|
1298
|
+
<pre class="terminal">$ kwalify -a genclass-ruby -P -f BABEL.schema.yaml \
|
1299
|
+
--hashlike --initialize=false --module=Babel
|
1300
|
+
require 'kwalify/util/hashlike'
|
1301
|
+
|
1302
|
+
module Babel
|
1303
|
+
|
1304
|
+
##
|
1305
|
+
class Team
|
1306
|
+
include Kwalify::Util::HashLike
|
1307
|
+
attr_accessor :name # str
|
1308
|
+
attr_accessor :desc # str
|
1309
|
+
attr_accessor :chief # map
|
1310
|
+
attr_accessor :members # seq
|
1311
|
+
end
|
1312
|
+
|
1313
|
+
##
|
1314
|
+
class Member
|
1315
|
+
include Kwalify::Util::HashLike
|
1316
|
+
attr_accessor :name # str
|
1317
|
+
attr_accessor :desc # str
|
1318
|
+
attr_accessor :team # map
|
1319
|
+
end
|
1320
|
+
|
1321
|
+
end
|
1322
|
+
$ kwalify -a genclass-ruby -P -f BABEL.schema.yaml \
|
1323
|
+
--hashlike --initialize=false --module=Babel > models.rb
|
1324
|
+
</pre>
|
1325
|
+
<p>Here is the ruby program.
|
1326
|
+
</p>
|
1327
|
+
<a name="loadbabel.rb"></a>
|
1328
|
+
<div class="program_caption">
|
1329
|
+
loadbabel.rb</div>
|
1330
|
+
<pre class="program">require 'kwalify'
|
1331
|
+
<strong>require 'models'</strong>
|
1332
|
+
|
1333
|
+
## load schema definition
|
1334
|
+
schema = Kwalify::Yaml.load_file('BABEL.schema.yaml',
|
1335
|
+
:untabify=>true,
|
1336
|
+
:preceding_alias=>true)
|
1337
|
+
|
1338
|
+
## add module name to 'class:'
|
1339
|
+
Kwalify::Util.traverse_schema(schema) do |rulehash|
|
1340
|
+
if rulehash['class']
|
1341
|
+
rulehash['class'] = 'Babel::' + rulehash['class']
|
1342
|
+
end
|
1343
|
+
end
|
1344
|
+
|
1345
|
+
## create validator
|
1346
|
+
validator = Kwalify::Validator.new(schema)
|
1347
|
+
|
1348
|
+
## parse with data-binding
|
1349
|
+
parser = Kwalify::Yaml::Parser.new(validator)
|
1350
|
+
parser.preceding_alias = true
|
1351
|
+
<strong>parser.data_binding = true</strong>
|
1352
|
+
ydoc = parser.parse_file('BABEL.data.yaml', :untabify=>true)
|
1353
|
+
|
1354
|
+
## show document
|
1355
|
+
require 'pp'
|
1356
|
+
pp ydoc
|
1357
|
+
</pre>
|
1358
|
+
<a name="howto5_databinding.result"></a>
|
1359
|
+
<div class="terminal_caption">
|
1360
|
+
result</div>
|
1361
|
+
<pre class="terminal">$ ruby loadbabel.rb
|
1362
|
+
{"teams"=>
|
1363
|
+
[#<Babel::Team:0x53e0f8
|
1364
|
+
@chief=
|
1365
|
+
#<Babel::Member:0x53d5e0
|
1366
|
+
@desc="Scientist",
|
1367
|
+
@name="Kohichi Minamoto",
|
1368
|
+
@team=#<Babel::Team:0x53e0f8 ...>>,
|
1369
|
+
@desc="Level 7 ESPers",
|
1370
|
+
@members=
|
1371
|
+
[#<Babel::Member:0x53d018
|
1372
|
+
@desc="Psychokino",
|
1373
|
+
@name="Kaoru Akashi",
|
1374
|
+
@team=#<Babel::Team:0x53e0f8 ...>>,
|
1375
|
+
#<Babel::Member:0x53ca50
|
1376
|
+
@desc="Teleporter",
|
1377
|
+
@name="Aoi Nogami",
|
1378
|
+
@team=#<Babel::Team:0x53e0f8 ...>>,
|
1379
|
+
#<Babel::Member:0x53c488
|
1380
|
+
@desc="Psycometrer",
|
1381
|
+
@name="Shiho Sannomiya",
|
1382
|
+
@team=#<Babel::Team:0x53e0f8 ...>>],
|
1383
|
+
@name="The Children">],
|
1384
|
+
"members"=>
|
1385
|
+
[#<Babel::Member:0x53d5e0
|
1386
|
+
@desc="Scientist",
|
1387
|
+
@name="Kohichi Minamoto",
|
1388
|
+
@team=
|
1389
|
+
#<Babel::Team:0x53e0f8
|
1390
|
+
@chief=#<Babel::Member:0x53d5e0 ...>,
|
1391
|
+
@desc="Level 7 ESPers",
|
1392
|
+
@members=
|
1393
|
+
[#<Babel::Member:0x53d018
|
1394
|
+
@desc="Psychokino",
|
1395
|
+
@name="Kaoru Akashi",
|
1396
|
+
@team=#<Babel::Team:0x53e0f8 ...>>,
|
1397
|
+
#<Babel::Member:0x53ca50
|
1398
|
+
@desc="Teleporter",
|
1399
|
+
@name="Aoi Nogami",
|
1400
|
+
@team=#<Babel::Team:0x53e0f8 ...>>,
|
1401
|
+
#<Babel::Member:0x53c488
|
1402
|
+
@desc="Psycometrer",
|
1403
|
+
@name="Shiho Sannomiya",
|
1404
|
+
@team=#<Babel::Team:0x53e0f8 ...>>],
|
1405
|
+
@name="The Children">>,
|
1406
|
+
#<Babel::Member:0x53d018
|
1407
|
+
@desc="Psychokino",
|
1408
|
+
@name="Kaoru Akashi",
|
1409
|
+
@team=
|
1410
|
+
#<Babel::Team:0x53e0f8
|
1411
|
+
@chief=
|
1412
|
+
#<Babel::Member:0x53d5e0
|
1413
|
+
@desc="Scientist",
|
1414
|
+
@name="Kohichi Minamoto",
|
1415
|
+
@team=#<Babel::Team:0x53e0f8 ...>>,
|
1416
|
+
@desc="Level 7 ESPers",
|
1417
|
+
@members=
|
1418
|
+
[#<Babel::Member:0x53d018 ...>,
|
1419
|
+
#<Babel::Member:0x53ca50
|
1420
|
+
@desc="Teleporter",
|
1421
|
+
@name="Aoi Nogami",
|
1422
|
+
@team=#<Babel::Team:0x53e0f8 ...>>,
|
1423
|
+
#<Babel::Member:0x53c488
|
1424
|
+
@desc="Psycometrer",
|
1425
|
+
@name="Shiho Sannomiya",
|
1426
|
+
@team=#<Babel::Team:0x53e0f8 ...>>],
|
1427
|
+
@name="The Children">>,
|
1428
|
+
#<Babel::Member:0x53ca50
|
1429
|
+
@desc="Teleporter",
|
1430
|
+
@name="Aoi Nogami",
|
1431
|
+
@team=
|
1432
|
+
#<Babel::Team:0x53e0f8
|
1433
|
+
@chief=
|
1434
|
+
#<Babel::Member:0x53d5e0
|
1435
|
+
@desc="Scientist",
|
1436
|
+
@name="Kohichi Minamoto",
|
1437
|
+
@team=#<Babel::Team:0x53e0f8 ...>>,
|
1438
|
+
@desc="Level 7 ESPers",
|
1439
|
+
@members=
|
1440
|
+
[#<Babel::Member:0x53d018
|
1441
|
+
@desc="Psychokino",
|
1442
|
+
@name="Kaoru Akashi",
|
1443
|
+
@team=#<Babel::Team:0x53e0f8 ...>>,
|
1444
|
+
#<Babel::Member:0x53ca50 ...>,
|
1445
|
+
#<Babel::Member:0x53c488
|
1446
|
+
@desc="Psycometrer",
|
1447
|
+
@name="Shiho Sannomiya",
|
1448
|
+
@team=#<Babel::Team:0x53e0f8 ...>>],
|
1449
|
+
@name="The Children">>,
|
1450
|
+
#<Babel::Member:0x53c488
|
1451
|
+
@desc="Psycometrer",
|
1452
|
+
@name="Shiho Sannomiya",
|
1453
|
+
@team=
|
1454
|
+
#<Babel::Team:0x53e0f8
|
1455
|
+
@chief=
|
1456
|
+
#<Babel::Member:0x53d5e0
|
1457
|
+
@desc="Scientist",
|
1458
|
+
@name="Kohichi Minamoto",
|
1459
|
+
@team=#<Babel::Team:0x53e0f8 ...>>,
|
1460
|
+
@desc="Level 7 ESPers",
|
1461
|
+
@members=
|
1462
|
+
[#<Babel::Member:0x53d018
|
1463
|
+
@desc="Psychokino",
|
1464
|
+
@name="Kaoru Akashi",
|
1465
|
+
@team=#<Babel::Team:0x53e0f8 ...>>,
|
1466
|
+
#<Babel::Member:0x53ca50
|
1467
|
+
@desc="Teleporter",
|
1468
|
+
@name="Aoi Nogami",
|
1469
|
+
@team=#<Babel::Team:0x53e0f8 ...>>,
|
1470
|
+
#<Babel::Member:0x53c488 ...>],
|
1471
|
+
@name="The Children">>]}
|
1472
|
+
</pre>
|
1473
|
+
<br>
|
1474
|
+
|
1475
|
+
|
1476
|
+
<br>
|
1477
|
+
|
1478
|
+
|
1479
|
+
<a name="actions"></a>
|
1480
|
+
<h2 class="section1">Actions</h2>
|
1481
|
+
<p>Kwalify has the command-line '-a <em>action</em>' which perform a certain action to schema definition.
|
1482
|
+
Currently only the following actions are provided.
|
1483
|
+
</p>
|
1484
|
+
<dl class="dl2">
|
1485
|
+
<dt class="dt2">
|
1486
|
+
genclass-ruby</dt>
|
1487
|
+
<dd class="dd2">
|
1488
|
+
<p> Generate class definitions in Ruby.
|
1258
1489
|
</p>
|
1259
|
-
<dl class="dl3">
|
1260
|
-
<dt class="dt3"><strong>
|
1261
|
-
genclass-ruby </strong></dt>
|
1262
|
-
<dd class="dd3">
|
1263
|
-
Generate class definitions in Ruby.
|
1264
1490
|
</dd>
|
1265
|
-
<dt class="
|
1266
|
-
genclass-java
|
1267
|
-
<dd class="
|
1268
|
-
Generate class definitions in Java.
|
1491
|
+
<dt class="dt2">
|
1492
|
+
genclass-java</dt>
|
1493
|
+
<dd class="dd2">
|
1494
|
+
<p> Generate class definitions in Java.
|
1495
|
+
</p>
|
1496
|
+
</dd>
|
1497
|
+
<dt class="dt2">
|
1498
|
+
genclass-php</dt>
|
1499
|
+
<dd class="dd2">
|
1500
|
+
<p> Generate class definitions in Ruby.
|
1501
|
+
</p>
|
1269
1502
|
</dd>
|
1270
1503
|
</dl>
|
1271
1504
|
<p>In fact action name represents template filename.
|
@@ -1275,6 +1508,9 @@ For example, action 'genclass-ruby' invokes template file 'kwalify/templates/gen
|
|
1275
1508
|
For example, action 'genclass-ruby' can accept the command-line properties '--module=<em>name</em>', '--parent=<em>name</em>', and so on.
|
1276
1509
|
Type 'kwalify -h -a <em>action</em>' to show the list of command-line properties the action can accept.
|
1277
1510
|
</p>
|
1511
|
+
<p>It is able to add your on action template file.
|
1512
|
+
The command-line option '-I' (template path) will help you.
|
1513
|
+
</p>
|
1278
1514
|
<a name="action-genclass"></a>
|
1279
1515
|
<h3 class="section2">Class Definition Generation</h3>
|
1280
1516
|
<p>Command-line option '-a genclass-ruby' or '-a genclass-java' generates class definition
|
@@ -1282,9 +1518,9 @@ automatically from schema definition in Ruby or Java.
|
|
1282
1518
|
</p>
|
1283
1519
|
<p>Assume the following data file and schema definition.
|
1284
1520
|
</p>
|
1285
|
-
<a name="
|
1521
|
+
<a name="address_book.yaml"></a>
|
1286
1522
|
<div class="program_caption">
|
1287
|
-
<code>
|
1523
|
+
<code>address_book.yaml</code> : data file</div>
|
1288
1524
|
<pre class="program">groups:
|
1289
1525
|
|
1290
1526
|
- name: family
|
@@ -1296,7 +1532,7 @@ automatically from schema definition in Ruby or Java.
|
|
1296
1532
|
- name: business
|
1297
1533
|
desc: those who works together
|
1298
1534
|
|
1299
|
-
|
1535
|
+
people:
|
1300
1536
|
|
1301
1537
|
- name: Sumire
|
1302
1538
|
group: family
|
@@ -1313,27 +1549,27 @@ persons:
|
|
1313
1549
|
email: cherry@mail.net
|
1314
1550
|
phone: 012-345-6789
|
1315
1551
|
</pre>
|
1316
|
-
<a name="
|
1552
|
+
<a name="address_book.schema.yaml"></a>
|
1317
1553
|
<div class="program_caption">
|
1318
|
-
<code>
|
1554
|
+
<code>address_book.schema.yaml</code> : schema definition file</div>
|
1319
1555
|
<pre class="program">type: map
|
1320
|
-
<strong>
|
1556
|
+
<strong>class: AddressBook</strong>
|
1321
1557
|
desc: address-book class
|
1322
1558
|
mapping:
|
1323
1559
|
"groups":
|
1324
1560
|
type: seq
|
1325
1561
|
sequence:
|
1326
1562
|
- type: map
|
1327
|
-
<strong>
|
1563
|
+
<strong>class: Group</strong>
|
1328
1564
|
desc: group class
|
1329
1565
|
mapping:
|
1330
1566
|
"name": { type: str, required: yes }
|
1331
1567
|
"desc": { type: str }
|
1332
|
-
"
|
1568
|
+
"people":
|
1333
1569
|
type: seq
|
1334
1570
|
sequence:
|
1335
1571
|
- type: map
|
1336
|
-
<strong>
|
1572
|
+
<strong>class: Person</strong>
|
1337
1573
|
desc: person class
|
1338
1574
|
mapping:
|
1339
1575
|
"name": { type: str, required: yes }
|
@@ -1343,81 +1579,95 @@ mapping:
|
|
1343
1579
|
"phone": { type: str }
|
1344
1580
|
"birth": { type: date }
|
1345
1581
|
"blood": { type: str, enum: [A, B, O, AB] }
|
1582
|
+
"deleted": { type: bool, <strong>default: false</strong> }
|
1346
1583
|
</pre>
|
1347
1584
|
<a name="action-genclass-ruby"></a>
|
1348
1585
|
<h4 class="section3">Ruby Class Definition</h4>
|
1349
1586
|
<div class="terminal_caption">
|
1350
1587
|
generate class definition</div>
|
1351
|
-
<pre class="terminal">$ kwalify <strong>-a genclass-ruby</strong> -tf
|
1588
|
+
<pre class="terminal">$ kwalify <strong>-a genclass-ruby</strong> -tf address_book.schema.yaml > address_book.rb
|
1352
1589
|
</pre>
|
1353
|
-
<a name="
|
1590
|
+
<a name="address_book.rb"></a>
|
1354
1591
|
<div class="program_caption">
|
1355
|
-
<code>
|
1592
|
+
<code>address_book.rb</code> : generated class definition</div>
|
1356
1593
|
<pre class="program">## address-book class
|
1357
1594
|
class AddressBook
|
1358
|
-
def initialize(hash)
|
1359
|
-
|
1360
|
-
|
1595
|
+
def initialize(hash=nil)
|
1596
|
+
if hash.nil?
|
1597
|
+
return
|
1598
|
+
end
|
1599
|
+
@groups = (v=hash['groups']) ? v.map!{|e| e.is_a?(Group) ? e : Group.new(e)} : v
|
1600
|
+
@people = (v=hash['people']) ? v.map!{|e| e.is_a?(Person) ? e : Person.new(e)} : v
|
1361
1601
|
end
|
1362
|
-
attr_accessor :
|
1363
|
-
attr_accessor :
|
1364
|
-
end
|
1365
|
-
|
1366
|
-
## person class
|
1367
|
-
class Person
|
1368
|
-
def initialize(hash)
|
1369
|
-
@name = hash['name']
|
1370
|
-
@desc = hash['desc']
|
1371
|
-
@phone = hash['phone']
|
1372
|
-
@blood = hash['blood']
|
1373
|
-
@group = hash['group']
|
1374
|
-
@birth = hash['birth']
|
1375
|
-
@email = hash['email']
|
1376
|
-
end
|
1377
|
-
attr_accessor :name # str
|
1378
|
-
attr_accessor :desc # str
|
1379
|
-
attr_accessor :phone # str
|
1380
|
-
attr_accessor :blood # str
|
1381
|
-
attr_accessor :group # str
|
1382
|
-
attr_accessor :birth # date
|
1383
|
-
attr_accessor :email # str
|
1602
|
+
attr_accessor :groups # seq
|
1603
|
+
attr_accessor :people # seq
|
1384
1604
|
end
|
1385
1605
|
|
1386
1606
|
## group class
|
1387
1607
|
class Group
|
1388
|
-
def initialize(hash)
|
1389
|
-
|
1390
|
-
|
1608
|
+
def initialize(hash=nil)
|
1609
|
+
if hash.nil?
|
1610
|
+
return
|
1611
|
+
end
|
1612
|
+
@name = hash['name']
|
1613
|
+
@desc = hash['desc']
|
1391
1614
|
end
|
1392
|
-
attr_accessor :name
|
1393
|
-
attr_accessor :desc
|
1615
|
+
attr_accessor :name # str
|
1616
|
+
attr_accessor :desc # str
|
1394
1617
|
end
|
1395
1618
|
|
1619
|
+
## person class
|
1620
|
+
class Person
|
1621
|
+
def initialize(hash=nil)
|
1622
|
+
if hash.nil?
|
1623
|
+
@deleted = false
|
1624
|
+
return
|
1625
|
+
end
|
1626
|
+
@name = hash['name']
|
1627
|
+
@desc = hash['desc']
|
1628
|
+
@group = hash['group']
|
1629
|
+
@email = hash['email']
|
1630
|
+
@phone = hash['phone']
|
1631
|
+
@birth = hash['birth']
|
1632
|
+
@blood = hash['blood']
|
1633
|
+
@deleted = (v=hash['deleted']).nil? ? false : v
|
1634
|
+
end
|
1635
|
+
attr_accessor :name # str
|
1636
|
+
attr_accessor :desc # str
|
1637
|
+
attr_accessor :group # str
|
1638
|
+
attr_accessor :email # str
|
1639
|
+
attr_accessor :phone # str
|
1640
|
+
attr_accessor :birth # date
|
1641
|
+
attr_accessor :blood # str
|
1642
|
+
attr_accessor :deleted # bool
|
1643
|
+
def deleted? ; @deleted ; end
|
1644
|
+
end
|
1396
1645
|
</pre>
|
1397
|
-
<a name="
|
1646
|
+
<a name="example_address_book.rb"></a>
|
1398
1647
|
<div class="program_caption">
|
1399
|
-
<code>
|
1400
|
-
<pre class="program">require '
|
1648
|
+
<code>example_address_book.rb</code> : example code of using address-book.rb</div>
|
1649
|
+
<pre class="program">require 'address_book'
|
1401
1650
|
require 'yaml'
|
1402
1651
|
require 'pp'
|
1403
1652
|
|
1404
|
-
str = File.read('
|
1653
|
+
str = File.read('address_book.yaml')
|
1405
1654
|
ydoc = YAML.load(str)
|
1406
1655
|
<strong>addrbook = AddressBook.new(ydoc)</strong>
|
1407
1656
|
|
1408
1657
|
pp <strong>addrbook.groups</strong>
|
1409
|
-
pp <strong>addrbook.
|
1658
|
+
pp <strong>addrbook.people</strong>
|
1410
1659
|
</pre>
|
1411
|
-
<a name="
|
1660
|
+
<a name="example_address_book_ruby.result"></a>
|
1412
1661
|
<div class="terminal_caption">
|
1413
1662
|
result</div>
|
1414
|
-
<pre class="terminal">$ ruby
|
1663
|
+
<pre class="terminal">$ ruby example_address_book.rb
|
1415
1664
|
[#<Group:0xddf24 @desc="my family", @name="family">,
|
1416
1665
|
#<Group:0xddf10 @desc="my friends", @name="friend">,
|
1417
1666
|
#<Group:0xdde84 @desc="those who works together", @name="business">]
|
1418
1667
|
[#<Person:0xdefdc
|
1419
1668
|
@birth=#<Date: 4903089/2,0,2299161>,
|
1420
1669
|
@blood="A",
|
1670
|
+
@deleted=false,
|
1421
1671
|
@desc=nil,
|
1422
1672
|
@email=nil,
|
1423
1673
|
@group="family",
|
@@ -1426,6 +1676,7 @@ result</div>
|
|
1426
1676
|
#<Person:0xdee9c
|
1427
1677
|
@birth=#<Date: 4899437/2,0,2299161>,
|
1428
1678
|
@blood=nil,
|
1679
|
+
@deleted=false,
|
1429
1680
|
@desc=nil,
|
1430
1681
|
@email="shiina@mail.org",
|
1431
1682
|
@group="friend",
|
@@ -1434,6 +1685,7 @@ result</div>
|
|
1434
1685
|
#<Person:0xde8e8
|
1435
1686
|
@birth=nil,
|
1436
1687
|
@blood=nil,
|
1688
|
+
@deleted=false,
|
1437
1689
|
@desc=nil,
|
1438
1690
|
@email="cherry@mail.net",
|
1439
1691
|
@group="business",
|
@@ -1442,37 +1694,40 @@ result</div>
|
|
1442
1694
|
</pre>
|
1443
1695
|
<p>Command-line option '<code>-h -a genclass-ruby</code>' shows the commpand-line properties that template can accept.
|
1444
1696
|
</p>
|
1445
|
-
<a name="option_ha.
|
1697
|
+
<a name="option_ha.result"></a>
|
1446
1698
|
<div class="terminal_caption">
|
1447
1699
|
show command-line properties</div>
|
1448
1700
|
<pre class="terminal">$ kwalify -ha genclass-ruby
|
1449
1701
|
--module=name : module name in which class defined
|
1450
1702
|
--parent=name : parent class name
|
1451
1703
|
--include=name : module name which all classes include
|
1704
|
+
--initialize=false : not print initialize() method
|
1705
|
+
--hashlike : include Kwalify::Util::HashLike module
|
1452
1706
|
</pre>
|
1453
1707
|
<div class="terminal_caption">
|
1454
1708
|
example of command-line properties</div>
|
1455
|
-
<pre class="terminal">$ kwalify -a genclass-ruby --module=My --
|
1709
|
+
<pre class="terminal">$ kwalify -a genclass-ruby --module=My --hashlike
|
1456
1710
|
</pre>
|
1457
|
-
<p>
|
1458
|
-
|
1711
|
+
<p>If command-line property '--hashlike' (== '--hashlike=true') is specified,
|
1712
|
+
module Kwalify::Util::HashLike is included for each classes generated.
|
1713
|
+
That module is defined in 'kwalify/util/hashlike.rb'
|
1459
1714
|
</p>
|
1460
1715
|
<br>
|
1461
1716
|
|
1462
1717
|
<a name="action-genclass-java"></a>
|
1463
1718
|
<h4 class="section3">Java Class Definition</h4>
|
1464
|
-
<a name="genclass_java.
|
1719
|
+
<a name="genclass_java.result"></a>
|
1465
1720
|
<div class="terminal_caption">
|
1466
1721
|
generate java class definition</div>
|
1467
|
-
<pre class="terminal">$ kwalify <strong>-a genclass-java</strong> -tf
|
1722
|
+
<pre class="terminal">$ kwalify <strong>-a genclass-java</strong> -tf address_book.schema.yaml
|
1468
1723
|
generating ./AddressBook.java...done.
|
1469
|
-
generating ./Person.java...done.
|
1470
1724
|
generating ./Group.java...done.
|
1725
|
+
generating ./Person.java...done.
|
1471
1726
|
</pre>
|
1472
1727
|
<a name="AddressBook.java.expected"></a>
|
1473
1728
|
<div class="program_caption">
|
1474
1729
|
<code>AddressBook.java</code> : generated class definition</div>
|
1475
|
-
<pre class="program">// generated by kwalify from
|
1730
|
+
<pre class="program">// generated by kwalify from address_book.schema.yaml
|
1476
1731
|
|
1477
1732
|
import java.util.*;
|
1478
1733
|
|
@@ -1481,42 +1736,42 @@ import java.util.*;
|
|
1481
1736
|
*/
|
1482
1737
|
public class AddressBook {
|
1483
1738
|
|
1484
|
-
private List _persons;
|
1485
1739
|
private List _groups;
|
1740
|
+
private List _people;
|
1486
1741
|
|
1487
1742
|
public AddressBook() {}
|
1488
1743
|
|
1489
1744
|
public AddressBook(Map map) {
|
1490
1745
|
List seq;
|
1491
1746
|
Object obj;
|
1492
|
-
if ((seq = (List)map.get("
|
1747
|
+
if ((seq = (List)map.get("groups")) != null) {
|
1493
1748
|
for (int i = 0; i < seq.size(); i++) {
|
1494
1749
|
if ((obj = seq.get(i)) instanceof Map) {
|
1495
|
-
seq.set(i, new
|
1750
|
+
seq.set(i, new Group((Map)obj));
|
1496
1751
|
}
|
1497
1752
|
}
|
1498
1753
|
}
|
1499
|
-
|
1500
|
-
if ((seq = (List)map.get("
|
1754
|
+
_groups = seq;
|
1755
|
+
if ((seq = (List)map.get("people")) != null) {
|
1501
1756
|
for (int i = 0; i < seq.size(); i++) {
|
1502
1757
|
if ((obj = seq.get(i)) instanceof Map) {
|
1503
|
-
seq.set(i, new
|
1758
|
+
seq.set(i, new Person((Map)obj));
|
1504
1759
|
}
|
1505
1760
|
}
|
1506
1761
|
}
|
1507
|
-
|
1762
|
+
_people = seq;
|
1508
1763
|
}
|
1509
1764
|
|
1510
|
-
public List getPersons() { return _persons; }
|
1511
|
-
public void setPersons(List persons_) { _persons = persons_; }
|
1512
1765
|
public List getGroups() { return _groups; }
|
1513
1766
|
public void setGroups(List groups_) { _groups = groups_; }
|
1767
|
+
public List getPeople() { return _people; }
|
1768
|
+
public void setPeople(List people_) { _people = people_; }
|
1514
1769
|
}
|
1515
1770
|
</pre>
|
1516
1771
|
<a name="Group.java.expected"></a>
|
1517
1772
|
<div class="program_caption">
|
1518
1773
|
<code>Group.java</code> : generated class definition</div>
|
1519
|
-
<pre class="program">// generated by kwalify from
|
1774
|
+
<pre class="program">// generated by kwalify from address_book.schema.yaml
|
1520
1775
|
|
1521
1776
|
import java.util.*;
|
1522
1777
|
|
@@ -1544,7 +1799,7 @@ public class Group {
|
|
1544
1799
|
<a name="Person.java.expected"></a>
|
1545
1800
|
<div class="program_caption">
|
1546
1801
|
<code>Person.java</code> : generated class definition</div>
|
1547
|
-
<pre class="program">// generated by kwalify from
|
1802
|
+
<pre class="program">// generated by kwalify from address_book.schema.yaml
|
1548
1803
|
|
1549
1804
|
import java.util.*;
|
1550
1805
|
|
@@ -1555,38 +1810,38 @@ public class Person {
|
|
1555
1810
|
|
1556
1811
|
private String _name;
|
1557
1812
|
private String _desc;
|
1558
|
-
private String _phone;
|
1559
|
-
private String _blood;
|
1560
1813
|
private String _group;
|
1561
|
-
private Date _birth;
|
1562
1814
|
private String _email;
|
1815
|
+
private String _phone;
|
1816
|
+
private Date _birth;
|
1817
|
+
private String _blood;
|
1563
1818
|
|
1564
1819
|
public Person() {}
|
1565
1820
|
|
1566
1821
|
public Person(Map map) {
|
1567
1822
|
_name = (String)map.get("name");
|
1568
1823
|
_desc = (String)map.get("desc");
|
1569
|
-
_phone = (String)map.get("phone");
|
1570
|
-
_blood = (String)map.get("blood");
|
1571
1824
|
_group = (String)map.get("group");
|
1572
|
-
_birth = (Date)map.get("birth");
|
1573
1825
|
_email = (String)map.get("email");
|
1826
|
+
_phone = (String)map.get("phone");
|
1827
|
+
_birth = (Date)map.get("birth");
|
1828
|
+
_blood = (String)map.get("blood");
|
1574
1829
|
}
|
1575
1830
|
|
1576
1831
|
public String getName() { return _name; }
|
1577
1832
|
public void setName(String name_) { _name = name_; }
|
1578
1833
|
public String getDesc() { return _desc; }
|
1579
1834
|
public void setDesc(String desc_) { _desc = desc_; }
|
1580
|
-
public String getPhone() { return _phone; }
|
1581
|
-
public void setPhone(String phone_) { _phone = phone_; }
|
1582
|
-
public String getBlood() { return _blood; }
|
1583
|
-
public void setBlood(String blood_) { _blood = blood_; }
|
1584
1835
|
public String getGroup() { return _group; }
|
1585
1836
|
public void setGroup(String group_) { _group = group_; }
|
1586
|
-
public Date getBirth() { return _birth; }
|
1587
|
-
public void setBirth(Date birth_) { _birth = birth_; }
|
1588
1837
|
public String getEmail() { return _email; }
|
1589
1838
|
public void setEmail(String email_) { _email = email_; }
|
1839
|
+
public String getPhone() { return _phone; }
|
1840
|
+
public void setPhone(String phone_) { _phone = phone_; }
|
1841
|
+
public Date getBirth() { return _birth; }
|
1842
|
+
public void setBirth(Date birth_) { _birth = birth_; }
|
1843
|
+
public String getBlood() { return _blood; }
|
1844
|
+
public void setBlood(String blood_) { _blood = blood_; }
|
1590
1845
|
}
|
1591
1846
|
</pre>
|
1592
1847
|
<a name="ExampleAddressBook.java"></a>
|
@@ -1598,12 +1853,12 @@ import kwalify.*;
|
|
1598
1853
|
public class ExampleAddressBook {
|
1599
1854
|
public static void main(String args[]) throws Exception {
|
1600
1855
|
// read schema
|
1601
|
-
String schema_str = Util.readFile("
|
1856
|
+
String schema_str = Util.readFile("address_book.schema.yaml");
|
1602
1857
|
schema_str = Util.untabify(schema_str);
|
1603
1858
|
Object schema = new YamlParser(schema_str).parse();
|
1604
1859
|
|
1605
1860
|
// read document file
|
1606
|
-
String document_str = Util.readFile("
|
1861
|
+
String document_str = Util.readFile("address_book.yaml");
|
1607
1862
|
document_str = Util.untabify(document_str);
|
1608
1863
|
YamlParser parser = new YamlParser(document_str);
|
1609
1864
|
Object document = parser.parse();
|
@@ -1622,10 +1877,10 @@ public class ExampleAddressBook {
|
|
1622
1877
|
}
|
1623
1878
|
}
|
1624
1879
|
|
1625
|
-
// show
|
1626
|
-
List
|
1627
|
-
if (
|
1628
|
-
for (Iterator it =
|
1880
|
+
// show people
|
1881
|
+
List people = addrbook.getPeople();
|
1882
|
+
if (people != null) {
|
1883
|
+
for (Iterator it = people.iterator(); it.hasNext(); ) {
|
1629
1884
|
Person person = (Person)it.next();
|
1630
1885
|
System.out.println("person name: " + person.getName());
|
1631
1886
|
System.out.println("person group: " + person.getGroup());
|
@@ -1640,7 +1895,7 @@ public class ExampleAddressBook {
|
|
1640
1895
|
|
1641
1896
|
}
|
1642
1897
|
</pre>
|
1643
|
-
<a name="
|
1898
|
+
<a name="example_address_book_java.result"></a>
|
1644
1899
|
<div class="terminal_caption">
|
1645
1900
|
result</div>
|
1646
1901
|
<pre class="terminal">$ javac -classpath '.:kwalify.jar' *.java
|
@@ -1678,7 +1933,7 @@ person birth: null
|
|
1678
1933
|
</pre>
|
1679
1934
|
<p>Command-line option '<code>-h -a genclass-java</code>' shows the commpand-line properties that template can accept.
|
1680
1935
|
</p>
|
1681
|
-
<a name="option_ha_genclass_java.
|
1936
|
+
<a name="option_ha_genclass_java.result"></a>
|
1682
1937
|
<div class="terminal_caption">
|
1683
1938
|
show command-line properties</div>
|
1684
1939
|
<pre class="terminal">$ kwalify -ha genclass-java
|
@@ -1687,6 +1942,7 @@ show command-line properties</div>
|
|
1687
1942
|
--implements=name,... : interface names to implement
|
1688
1943
|
--dir=path : directory to locate output file
|
1689
1944
|
--basedir=path : base directory to locate output file
|
1945
|
+
--constructor=false : not print initialize() method
|
1690
1946
|
</pre>
|
1691
1947
|
<div class="terminal_caption">
|
1692
1948
|
example of command-line properties</div>
|
@@ -1700,25 +1956,16 @@ example of command-line properties</div>
|
|
1700
1956
|
<br>
|
1701
1957
|
|
1702
1958
|
|
1703
|
-
<a name="
|
1704
|
-
<h2 class="section1">
|
1705
|
-
<a name="
|
1959
|
+
<a name="ref"></a>
|
1960
|
+
<h2 class="section1">References</h2>
|
1961
|
+
<a name="ref-usage"></a>
|
1706
1962
|
<h3 class="section2">Usage in Command-Line</h3>
|
1707
1963
|
<div class="terminal_caption">
|
1708
|
-
|
1709
|
-
<pre class="terminal">###
|
1964
|
+
</div>
|
1965
|
+
<pre class="terminal">### usage1: validate YAML document in command-line
|
1710
1966
|
$ kwalify -f schema.yaml document.yaml [document2.yaml ...]
|
1711
|
-
|
1712
|
-
### kwalify-java
|
1713
|
-
$ java -classpath kwalify.jar kwalify.Main -f schema.yaml document.yaml [document2.yaml ...]
|
1714
|
-
</pre>
|
1715
|
-
<div class="terminal_caption">
|
1716
|
-
usage2: validate schema definition in command-line</div>
|
1717
|
-
<pre class="terminal">### kwalify-ruby
|
1967
|
+
### usage2: validate schema definition in command-line
|
1718
1968
|
$ kwalify -m schema.yaml [schema2.yaml ...]
|
1719
|
-
|
1720
|
-
### kwalify-java
|
1721
|
-
$ java -classpath kwalify.jar kwalify.Main -m schema.yaml [schema2.yaml ...]
|
1722
1969
|
</pre>
|
1723
1970
|
<p>Command-line options:
|
1724
1971
|
</p>
|
@@ -1734,9 +1981,14 @@ $ java -classpath kwalify.jar kwalify.Main -m schema.yaml [schema2.yaml ...]
|
|
1734
1981
|
Print version.
|
1735
1982
|
</dd>
|
1736
1983
|
<dt class="dt3"><strong>
|
1984
|
+
<code>-q</code> </strong></dt>
|
1985
|
+
<dd class="dd3">
|
1986
|
+
Quiet mode.
|
1987
|
+
</dd>
|
1988
|
+
<dt class="dt3"><strong>
|
1737
1989
|
<code>-s</code> </strong></dt>
|
1738
1990
|
<dd class="dd3">
|
1739
|
-
Silent mode.
|
1991
|
+
(Obsolete. Use '-q' instead.) Silent mode.
|
1740
1992
|
</dd>
|
1741
1993
|
<dt class="dt3"><strong>
|
1742
1994
|
<code>-f <em>schema.yaml</em></code> </strong></dt>
|
@@ -1769,104 +2021,17 @@ $ java -classpath kwalify.jar kwalify.Main -m schema.yaml [schema2.yaml ...]
|
|
1769
2021
|
Do action. Currently supported action is 'genclass-ruby' and 'genclass-java'.
|
1770
2022
|
Try '-ha action' to get help about the action.
|
1771
2023
|
</dd>
|
2024
|
+
<dt class="dt3"><strong>
|
2025
|
+
<code>-I path1,path2,...</code> </strong></dt>
|
2026
|
+
<dd class="dd3">
|
2027
|
+
Template path (for '-a').
|
2028
|
+
</dd>
|
2029
|
+
<dt class="dt3"><strong>
|
2030
|
+
<code>-P</code> </strong></dt>
|
2031
|
+
<dd class="dd3">
|
2032
|
+
Enable preceding alias.
|
2033
|
+
</dd>
|
1772
2034
|
</dl>
|
1773
|
-
<p>Notice that the command-line option <code>-l</code> is an experimental feature, for kwalify command use original YAML parser instead of Syck parser when this option is specified.
|
1774
|
-
</p>
|
1775
|
-
<p>If you are an Emacs user, try <code>-E</code> option that show errors in format which Emacs can parse and jump to errors.
|
1776
|
-
You can use <code>C-x `</code> (next-error) to jump into errors.
|
1777
|
-
</p>
|
1778
|
-
<br>
|
1779
|
-
|
1780
|
-
|
1781
|
-
<a name="usage-ruby"></a>
|
1782
|
-
<h3 class="section2">Usage in Ruby Script</h3>
|
1783
|
-
<p>The followings are example scripts for Ruby.
|
1784
|
-
</p>
|
1785
|
-
<div class="program_caption">
|
1786
|
-
validate YAML document in Ruby script</div>
|
1787
|
-
<pre class="program">require 'kwalify'
|
1788
|
-
|
1789
|
-
## parse schema definition and create validator
|
1790
|
-
schema = YAML.load_file('schema.yaml')
|
1791
|
-
validator = Kwalify::Validator.new(schema) # raises Kwalify::SchemaError if wrong
|
1792
|
-
|
1793
|
-
## validate YAML document
|
1794
|
-
document = YAML.load_file('document.yaml')
|
1795
|
-
error_list = validator.validate(document)
|
1796
|
-
unless error_list.empty?
|
1797
|
-
error_list.each do |error| # error is instance of Kwalify::ValidationError
|
1798
|
-
puts "[#{error.path}] #{error.message}"
|
1799
|
-
end
|
1800
|
-
end
|
1801
|
-
</pre>
|
1802
|
-
<div class="program_caption">
|
1803
|
-
validate YAML document and show linenumber on where error is found.</div>
|
1804
|
-
<pre class="program">require 'kwalify'
|
1805
|
-
|
1806
|
-
## parse schema definition and create validator
|
1807
|
-
schema = YAML.load_file('schema.yaml')
|
1808
|
-
validator = Kwalify::Validator.new(schema) # raises Kwalify::SchemaError if wrong
|
1809
|
-
|
1810
|
-
## parse YAML document with Kwalify's parser
|
1811
|
-
str = File.read('document.yaml')
|
1812
|
-
parser = Kwalify::Parser.new(str)
|
1813
|
-
document = parser.parse()
|
1814
|
-
|
1815
|
-
## validate document and show errors
|
1816
|
-
error_list = validator.validate(document)
|
1817
|
-
unless error_list.empty?
|
1818
|
-
parser.set_errors_linenum(error_list) # set linenum on error
|
1819
|
-
error_list.sort.each do |error|
|
1820
|
-
puts "(line %d)[%s] %s" % [error.linenum, error.path, error.message]
|
1821
|
-
end
|
1822
|
-
end
|
1823
|
-
</pre>
|
1824
|
-
<p>Kwalify's YAML parser is experimental. You should notice that Kwalify's YAML parser is limited only for basic syntax of YAML.
|
1825
|
-
</p>
|
1826
|
-
<br>
|
1827
|
-
|
1828
|
-
|
1829
|
-
<a name="usage-java"></a>
|
1830
|
-
<h3 class="section2">Usage in Java Program</h3>
|
1831
|
-
<p>The followings are example programs of Java.
|
1832
|
-
</p>
|
1833
|
-
<div class="program_caption">
|
1834
|
-
validate YAML document and show linenumber on where error is found.</div>
|
1835
|
-
<pre class="program">import kwalify.*;
|
1836
|
-
|
1837
|
-
public class Test {
|
1838
|
-
|
1839
|
-
public static void main(String[] args) throws Exception {
|
1840
|
-
// read schema
|
1841
|
-
String schema_str = Util.readFile("schema.yaml");
|
1842
|
-
schema_str = Util.untabify(schema_str);
|
1843
|
-
Object schema = new YamlParser(schema_str).parse();
|
1844
|
-
|
1845
|
-
// read document file
|
1846
|
-
String document_str = Util.readFile("document.yaml");
|
1847
|
-
document_str = Util.untabify(document_str);
|
1848
|
-
YamlParser parser = new YamlParser(document_str);
|
1849
|
-
Object document = parser.parse();
|
1850
|
-
|
1851
|
-
// create validator and validate
|
1852
|
-
Validator validator = new Validator(schema);
|
1853
|
-
List errors = validator.validate(document);
|
1854
|
-
|
1855
|
-
// show errors
|
1856
|
-
if (errors != null && errors.size() > 0) {
|
1857
|
-
parser.setErrorsLineNumber(errors);
|
1858
|
-
Collections.sort(errors);
|
1859
|
-
for (Iterator it = errors.iterator(); it.hasNext(); ) {
|
1860
|
-
ValidationException error = (ValidationException)it.next();
|
1861
|
-
int linenum = error.getLineNumber();
|
1862
|
-
String path = error.getPath();
|
1863
|
-
String mesg = error.getMessage();
|
1864
|
-
System.out.println("- " + linenum + ": [" + path + "] " + mesg);
|
1865
|
-
}
|
1866
|
-
}
|
1867
|
-
}
|
1868
|
-
}
|
1869
|
-
</pre>
|
1870
2035
|
<br>
|
1871
2036
|
|
1872
2037
|
|