kwalify 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +15 -4
- data/README.txt +8 -10
- data/bin/kwalify +1 -1
- data/contrib/inline-require +1 -1
- data/contrib/kwalify +47 -30
- data/doc-api/classes/CommandOptionError.html +1 -1
- data/doc-api/classes/Kwalify.html +1 -1
- data/doc-api/classes/Kwalify/BaseError.html +1 -1
- data/doc-api/classes/Kwalify/Validator.html +4 -1
- data/doc-api/classes/Kwalify/Yaml.html +26 -13
- data/doc-api/classes/Kwalify/Yaml/Parser.html +17 -17
- data/doc-api/created.rid +1 -1
- data/doc-api/files/__/README_txt.html +9 -11
- data/doc-api/files/kwalify/errors_rb.html +2 -2
- data/doc-api/files/kwalify/main_rb.html +1 -1
- data/doc-api/files/kwalify/messages_rb.html +2 -2
- data/doc-api/files/kwalify/meta-validator_rb.html +1 -1
- data/doc-api/files/kwalify/parser/base_rb.html +1 -1
- data/doc-api/files/kwalify/parser/yaml_rb.html +2 -2
- data/doc-api/files/kwalify/rule_rb.html +1 -1
- data/doc-api/files/kwalify/types_rb.html +1 -1
- data/doc-api/files/kwalify/util/assert-text-equal_rb.html +1 -1
- data/doc-api/files/kwalify/util/hash-interface_rb.html +1 -1
- data/doc-api/files/kwalify/util/hashlike_rb.html +1 -1
- data/doc-api/files/kwalify/util/option-parser_rb.html +1 -1
- data/doc-api/files/kwalify/util/ordered-hash_rb.html +1 -1
- data/doc-api/files/kwalify/util/testcase-helper_rb.html +1 -1
- data/doc-api/files/kwalify/util_rb.html +1 -1
- data/doc-api/files/kwalify/validator_rb.html +2 -2
- data/doc-api/files/kwalify/yaml-parser_rb.html +1 -1
- data/doc-api/files/kwalify_rb.html +2 -2
- data/doc/users-guide.html +20 -15
- data/examples/address-book/address-book.schema.yaml +1 -1
- data/examples/invoice/invoice.schema.yaml +1 -1
- data/examples/tapkit/tapkit.schema.yaml +1 -1
- data/lib/kwalify.rb +22 -12
- data/lib/kwalify/errors.rb +3 -3
- data/lib/kwalify/main.rb +1 -1
- data/lib/kwalify/messages.rb +1 -1
- data/lib/kwalify/meta-validator.rb +1 -1
- data/lib/kwalify/parser/base.rb +1 -1
- data/lib/kwalify/parser/yaml.rb +7 -3
- data/lib/kwalify/rule.rb +1 -1
- data/lib/kwalify/templates/genclass-java.eruby +1 -1
- data/lib/kwalify/templates/genclass-php.eruby +1 -1
- data/lib/kwalify/templates/genclass-ruby.eruby +1 -1
- data/lib/kwalify/types.rb +1 -1
- data/lib/kwalify/util.rb +1 -1
- data/lib/kwalify/util/assert-text-equal.rb +1 -1
- data/lib/kwalify/util/hash-interface.rb +1 -1
- data/lib/kwalify/util/hashlike.rb +1 -1
- data/lib/kwalify/util/option-parser.rb +1 -1
- data/lib/kwalify/util/ordered-hash.rb +1 -1
- data/lib/kwalify/util/testcase-helper.rb +1 -1
- data/lib/kwalify/validator.rb +5 -2
- data/lib/kwalify/yaml-parser.rb +1 -1
- data/test/data/users-guide/answers-validator.rb +9 -9
- data/test/data/users-guide/howto-validation.rb +2 -2
- data/test/data/users-guide/invalid07.result +1 -1
- data/test/data/users-guide/loadconfig.rb +2 -1
- data/test/data/users-guide/loadconfig.result +5 -1
- data/test/test-action.rb +1 -1
- data/test/test-action.yaml +1 -1
- data/test/test-databinding.rb +6 -3
- data/test/test-databinding.yaml +39 -1
- data/test/test-main.rb +1 -1
- data/test/test-main.yaml +1 -1
- data/test/test-metavalidator.rb +1 -1
- data/test/test-metavalidator.yaml +1 -1
- data/test/test-parser-yaml.rb +1 -1
- data/test/test-parser-yaml.yaml +1 -1
- data/test/test-rule.rb +1 -1
- data/test/test-rule.yaml +1 -1
- data/test/test-validator.rb +1 -1
- data/test/test-validator.yaml +1 -1
- data/test/test-yaml-parser.rb +1 -1
- data/test/test-yaml-parser.yaml +1 -1
- data/test/test.rb +1 -1
- metadata +2 -2
data/doc-api/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Mon, 28 Jan 2008 16:57:37 +0900
|
@@ -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>Mon Jan 28 15:27:13 +0900 2008</td>
|
60
60
|
</tr>
|
61
61
|
</table>
|
62
62
|
</div>
|
@@ -71,10 +71,10 @@
|
|
71
71
|
<div id="description">
|
72
72
|
<h1>README</h1>
|
73
73
|
<table>
|
74
|
-
<tr><td valign="top">release:</td><td>0.7.
|
74
|
+
<tr><td valign="top">release:</td><td>0.7.1
|
75
75
|
|
76
76
|
</td></tr>
|
77
|
-
<tr><td valign="top">lastupdate:</td><td>$Date: 2008-01-
|
77
|
+
<tr><td valign="top">lastupdate:</td><td>$Date: 2008-01-28 15:27:12 +0900 (Mon, 28 Jan 2008) $
|
78
78
|
|
79
79
|
</td></tr>
|
80
80
|
<tr><td valign="top">copyright:</td><td>copyright(c) 2005-2008 kuwata-lab all rights reserved.
|
@@ -100,18 +100,16 @@ If you have installed RubyGems, just type ‘gem install kwalify‘
|
|
100
100
|
Else if you can be root user, use ‘setup.rb’ as following:
|
101
101
|
</p>
|
102
102
|
<pre>
|
103
|
-
$ tar xjf
|
104
|
-
$ cd
|
105
|
-
$ ruby setup.rb config
|
106
|
-
$ ruby setup.rb setup
|
103
|
+
$ tar xjf kwalify-0.7.1.tar.bz2
|
104
|
+
$ cd kwalify-0.7.1/
|
107
105
|
$ sudo ruby setup.rb install
|
108
106
|
</pre>
|
109
107
|
<p>
|
110
108
|
Else copy script and libraries to proper directory.
|
111
109
|
</p>
|
112
110
|
<pre>
|
113
|
-
$ tar xjf
|
114
|
-
$ cd
|
111
|
+
$ tar xjf kwalify-0.7.1.tar.bz2
|
112
|
+
$ cd kwalify-0.7.1/
|
115
113
|
$ mkdir -p $HOME/bin
|
116
114
|
$ cp -a bin/* $HOME/bin
|
117
115
|
$ export PATH=$PATH:$HOME/bin
|
@@ -124,8 +122,8 @@ Else copy script and libraries to proper directory.
|
|
124
122
|
script and libraries into a file.
|
125
123
|
</p>
|
126
124
|
<pre>
|
127
|
-
$ tar xjf
|
128
|
-
$ cd
|
125
|
+
$ tar xjf kwalify-0.7.1.tar.bz2
|
126
|
+
$ cd kwalify-0.7.1/
|
129
127
|
$ unset RUBYLIB
|
130
128
|
$ ruby contrib/inline-require -I ./lib bin/kwalify > contrib/kwalify
|
131
129
|
$ chmod a+x contrib/kwalify
|
@@ -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>Mon Jan 28 15:27:13 +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: 99 $ $Release: 0.7.1 $ 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>
|
59
|
+
<td>Mon Jan 28 16:57:37 +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: 95 $ $Release: 0.7.
|
73
|
+
$Rev: 95 $ $Release: 0.7.1 $ 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>
|
59
|
+
<td>Mon Jan 28 15:27:13 +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: 99 $ $Release: 0.7.1 $ 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>
|
59
|
+
<td>Mon Jan 28 15:27:13 +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: 99 $ $Release: 0.7.1 $ 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>
|
59
|
+
<td>Mon Jan 28 15:27:13 +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: 99 $ $Release: 0.7.1 $ copyright(c) 2006 kuwata-lab.com all rights
|
74
74
|
reserved.
|
75
75
|
</p>
|
76
76
|
|
data/doc/users-guide.html
CHANGED
@@ -15,7 +15,7 @@
|
|
15
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: 2008-01-
|
18
|
+
last update: $Date: 2008-01-28 15:27:12 +0900 (Mon, 28 Jan 2008) $<br>
|
19
19
|
</div>
|
20
20
|
|
21
21
|
<a name="preface"></a>
|
@@ -931,8 +931,8 @@ errors = validator.validate(document)
|
|
931
931
|
|
932
932
|
## show errors
|
933
933
|
if errors && !errors.empty?
|
934
|
-
for
|
935
|
-
puts "[#{
|
934
|
+
for e in errors
|
935
|
+
puts "[#{e.path}] #{e.message}"
|
936
936
|
end
|
937
937
|
end
|
938
938
|
</pre>
|
@@ -1063,20 +1063,20 @@ end
|
|
1063
1063
|
## create validator
|
1064
1064
|
validator = AnswersValidator.new
|
1065
1065
|
|
1066
|
-
##
|
1066
|
+
## parse and validate YAML document
|
1067
1067
|
input = ARGF.read()
|
1068
|
-
|
1069
|
-
|
1068
|
+
parser = Kwalify::Yaml::Parser.new(validator)
|
1069
|
+
document = parser.parse(input)
|
1070
1070
|
|
1071
|
-
##
|
1072
|
-
errors =
|
1073
|
-
if errors.empty?
|
1071
|
+
## show errors
|
1072
|
+
errors = parser.errors()
|
1073
|
+
if !errors || errors.empty?
|
1074
1074
|
puts "Valid."
|
1075
1075
|
else
|
1076
1076
|
puts "*** INVALID!"
|
1077
|
-
|
1078
|
-
#
|
1079
|
-
puts "
|
1077
|
+
for e in errors
|
1078
|
+
# e.class == Kwalify::ValidationError
|
1079
|
+
puts "#{e.linenum}:#{e.column} [#{e.path}] #{e.message}"
|
1080
1080
|
end
|
1081
1081
|
end
|
1082
1082
|
</pre>
|
@@ -1115,7 +1115,7 @@ Valid.
|
|
1115
1115
|
validate</div>
|
1116
1116
|
<pre class="terminal">$ ruby answers-validator.rb document07b.yaml
|
1117
1117
|
*** INVALID!
|
1118
|
-
|
1118
|
+
4:3 [/answers/1] reason is required when answer is 'bad'.
|
1119
1119
|
</pre>
|
1120
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
1121
|
</p>
|
@@ -1212,13 +1212,18 @@ validator = Kwalify::Validator.new(schema)
|
|
1212
1212
|
parser = Kwalify::Yaml::Parser.new(validator)
|
1213
1213
|
<strong>parser.data_binding = true</strong> # enable data binding
|
1214
1214
|
config = parser.parse_file('config.yaml')
|
1215
|
-
|
1215
|
+
require 'pp'
|
1216
|
+
pp config
|
1216
1217
|
</pre>
|
1217
1218
|
<a name="loadconfig.result"></a>
|
1218
1219
|
<div class="terminal_caption">
|
1219
1220
|
result</div>
|
1220
1221
|
<pre class="terminal">$ ruby loadconfig.rb
|
1221
|
-
#<Config:
|
1222
|
+
#<Config:
|
1223
|
+
@host="localhost",
|
1224
|
+
@pass="password1",
|
1225
|
+
@port=8080,
|
1226
|
+
@user="user1">
|
1222
1227
|
</pre>
|
1223
1228
|
<p>Data binding is available even when data is more complex.
|
1224
1229
|
Preceding alias is also available.
|
data/lib/kwalify.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
###
|
2
|
-
### $Rev:
|
3
|
-
### $Release: 0.7.
|
2
|
+
### $Rev: 99 $
|
3
|
+
### $Release: 0.7.1 $
|
4
4
|
### copyright(c) 2006 kuwata-lab.com all rights reserved.
|
5
5
|
###
|
6
6
|
|
7
7
|
|
8
8
|
module Kwalify
|
9
9
|
|
10
|
-
RELEASE = ("$Release: 0.7.
|
10
|
+
RELEASE = ("$Release: 0.7.1 $" =~ /[.\d]+/) && $&
|
11
11
|
|
12
12
|
end
|
13
13
|
|
@@ -34,19 +34,29 @@ module Kwalify
|
|
34
34
|
|
35
35
|
autoload :Parser, 'kwalify/parser/yaml'
|
36
36
|
|
37
|
-
|
37
|
+
## read yaml_str, parse it, and return yaml document.
|
38
|
+
##
|
39
|
+
## opts:
|
40
|
+
## ::validator: Kwalify::Validator object
|
41
|
+
## ::preceding_aliass: allow preceding alias if true
|
42
|
+
## ::data_binding: enable data binding if true
|
43
|
+
## ::untabify: expand tab chars if true
|
44
|
+
## ::filename: filename
|
45
|
+
def self.load(yaml_str, opts={})
|
38
46
|
#require 'kwalify/parser/yaml'
|
39
|
-
parser = Kwalify::Yaml::Parser.new
|
40
|
-
parser.preceding_alias = true if
|
41
|
-
parser.data_binding = true if
|
42
|
-
yaml_str = Kwalify::Util.untabify(yaml_str) if
|
43
|
-
ydoc = parser.parse(yaml_str, :filename=>
|
47
|
+
parser = Kwalify::Yaml::Parser.new(opts[:validator])
|
48
|
+
parser.preceding_alias = true if opts[:preceding_alias]
|
49
|
+
parser.data_binding = true if opts[:data_binding]
|
50
|
+
yaml_str = Kwalify::Util.untabify(yaml_str) if opts[:untabify]
|
51
|
+
ydoc = parser.parse(yaml_str, :filename=>opts[:filename])
|
44
52
|
return ydoc
|
45
53
|
end
|
46
54
|
|
47
|
-
|
48
|
-
|
49
|
-
|
55
|
+
## read file, parse it, and return yaml document.
|
56
|
+
## see Kwalify::Yaml::Parser.load()
|
57
|
+
def self.load_file(filename, opts={})
|
58
|
+
opts[:filename] = filename
|
59
|
+
return self.load(File.read(filename), opts)
|
50
60
|
end
|
51
61
|
|
52
62
|
end
|
data/lib/kwalify/errors.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
###
|
2
|
-
### $Rev:
|
3
|
-
### $Release: 0.7.
|
2
|
+
### $Rev: 99 $
|
3
|
+
### $Release: 0.7.1 $
|
4
4
|
### copyright(c) 2005-2008 kuwata-lab all rights reserved.
|
5
5
|
###
|
6
6
|
|
@@ -22,7 +22,7 @@ module Kwalify
|
|
22
22
|
class BaseError < KwalifyError
|
23
23
|
def initialize(message="", path=nil, value=nil, rule=nil, error_symbol=nil)
|
24
24
|
super(message)
|
25
|
-
@path = path
|
25
|
+
@path = path.is_a?(Array) ? '/'+path.join('/') : path
|
26
26
|
@rule = rule
|
27
27
|
@value = value
|
28
28
|
@error_symbol = error_symbol
|