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/lib/kwalify/main.rb
CHANGED
data/lib/kwalify/messages.rb
CHANGED
data/lib/kwalify/parser/base.rb
CHANGED
data/lib/kwalify/parser/yaml.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
|
|
@@ -336,8 +336,12 @@ class Kwalify::Yaml::Parser < Kwalify::BaseParser
|
|
336
336
|
_linenum, _column, _linenum2, _column2) #:nodoc:
|
337
337
|
key = to_mapkey(key)
|
338
338
|
path[-1] = key
|
339
|
+
#if map.is_a?(Hash) && map.key?(key) && !is_merged
|
339
340
|
if map.respond_to?('key?') && map.key?(key) && !is_merged
|
340
|
-
|
341
|
+
rule = map_rule.mapping[key]
|
342
|
+
unless rule && rule.default
|
343
|
+
raise _syntax_error("mapping key is duplicated.", path)
|
344
|
+
end
|
341
345
|
end
|
342
346
|
#
|
343
347
|
if key == '=' # default
|
data/lib/kwalify/rule.rb
CHANGED
data/lib/kwalify/types.rb
CHANGED
data/lib/kwalify/util.rb
CHANGED
data/lib/kwalify/validator.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
|
|
@@ -113,6 +113,9 @@ module Kwalify
|
|
113
113
|
end
|
114
114
|
return unless errors.length == n
|
115
115
|
#
|
116
|
+
#path_str = path.is_a?(Array) ? '/'+path.join('/') : path
|
117
|
+
#validate_hook(value, rule, path_str, errors)
|
118
|
+
#@block.call(value, rule, path_str, errors) if @block
|
116
119
|
validate_hook(value, rule, path, errors)
|
117
120
|
@block.call(value, rule, path, errors) if @block
|
118
121
|
end
|
data/lib/kwalify/yaml-parser.rb
CHANGED
@@ -34,19 +34,19 @@ end
|
|
34
34
|
## create validator
|
35
35
|
validator = AnswersValidator.new
|
36
36
|
|
37
|
-
##
|
37
|
+
## parse and validate YAML document
|
38
38
|
input = ARGF.read()
|
39
|
-
|
40
|
-
|
39
|
+
parser = Kwalify::Yaml::Parser.new(validator)
|
40
|
+
document = parser.parse(input)
|
41
41
|
|
42
|
-
##
|
43
|
-
errors =
|
44
|
-
if errors.empty?
|
42
|
+
## show errors
|
43
|
+
errors = parser.errors()
|
44
|
+
if !errors || errors.empty?
|
45
45
|
puts "Valid."
|
46
46
|
else
|
47
47
|
puts "*** INVALID!"
|
48
|
-
|
49
|
-
#
|
50
|
-
puts "
|
48
|
+
for e in errors
|
49
|
+
# e.class == Kwalify::ValidationError
|
50
|
+
puts "#{e.linenum}:#{e.column} [#{e.path}] #{e.message}"
|
51
51
|
end
|
52
52
|
end
|
data/test/test-action.rb
CHANGED
data/test/test-action.yaml
CHANGED
data/test/test-databinding.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
|
|
@@ -45,7 +45,10 @@ class DataBindingTest < Test::Unit::TestCase
|
|
45
45
|
#@schema = YAML.load(Kwalify::Util.untabify(@schema))
|
46
46
|
end
|
47
47
|
## data binding
|
48
|
-
|
48
|
+
#Object.class_eval {@classdef} if @classdef
|
49
|
+
if @classdef
|
50
|
+
Object.class_eval @classdef
|
51
|
+
end
|
49
52
|
validator = Kwalify::Validator.new(@schema)
|
50
53
|
parser = Kwalify::Yaml::Parser.new(validator, :data_binding=>true)
|
51
54
|
@testopts ||= {}
|
data/test/test-databinding.yaml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
##
|
2
2
|
## $Rev: 63 $
|
3
|
-
## $Release: 0.7.
|
3
|
+
## $Release: 0.7.1 $
|
4
4
|
## copyright(c) 2005-2008 kuwata-lab all rights reserved.
|
5
5
|
##
|
6
6
|
---
|
@@ -299,3 +299,41 @@
|
|
299
299
|
- [ "/users/2/manager/name", 18, 17 ]
|
300
300
|
- [ "/users/3", 17, 5 ]
|
301
301
|
- [ "/users/3/name", 18, 17 ]
|
302
|
+
|
303
|
+
|
304
|
+
- name: databind4
|
305
|
+
desc: default value
|
306
|
+
schema: |
|
307
|
+
type: map
|
308
|
+
class: Config
|
309
|
+
mapping:
|
310
|
+
"host": {type: str, default: localhost}
|
311
|
+
"port": {type: int, default: 80}
|
312
|
+
"user": {type: str, required: true}
|
313
|
+
"pass": {type: str, required: true}
|
314
|
+
|
315
|
+
classdef*:
|
316
|
+
"ruby": |
|
317
|
+
require 'kwalify/util/hashlike'
|
318
|
+
class Config
|
319
|
+
include Kwalify::Util::HashLike
|
320
|
+
def initialize
|
321
|
+
@host = 'localhost'
|
322
|
+
@port = 8080
|
323
|
+
end
|
324
|
+
attr_accessor :host, :port, :user, :pass
|
325
|
+
end
|
326
|
+
"java": |
|
327
|
+
data: |
|
328
|
+
#host: localhost
|
329
|
+
port: 8080
|
330
|
+
user: user1
|
331
|
+
pass: password1
|
332
|
+
expected*:
|
333
|
+
"ruby": |
|
334
|
+
#<Config:0x001
|
335
|
+
@host="localhost",
|
336
|
+
@pass="password1",
|
337
|
+
@port=8080,
|
338
|
+
@user="user1">
|
339
|
+
locations:
|
data/test/test-main.rb
CHANGED
data/test/test-main.yaml
CHANGED
data/test/test-metavalidator.rb
CHANGED
data/test/test-parser-yaml.rb
CHANGED
data/test/test-parser-yaml.yaml
CHANGED
data/test/test-rule.rb
CHANGED
data/test/test-rule.yaml
CHANGED
data/test/test-validator.rb
CHANGED
data/test/test-validator.yaml
CHANGED