kwalify 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/CHANGES.txt +15 -4
  2. data/README.txt +8 -10
  3. data/bin/kwalify +1 -1
  4. data/contrib/inline-require +1 -1
  5. data/contrib/kwalify +47 -30
  6. data/doc-api/classes/CommandOptionError.html +1 -1
  7. data/doc-api/classes/Kwalify.html +1 -1
  8. data/doc-api/classes/Kwalify/BaseError.html +1 -1
  9. data/doc-api/classes/Kwalify/Validator.html +4 -1
  10. data/doc-api/classes/Kwalify/Yaml.html +26 -13
  11. data/doc-api/classes/Kwalify/Yaml/Parser.html +17 -17
  12. data/doc-api/created.rid +1 -1
  13. data/doc-api/files/__/README_txt.html +9 -11
  14. data/doc-api/files/kwalify/errors_rb.html +2 -2
  15. data/doc-api/files/kwalify/main_rb.html +1 -1
  16. data/doc-api/files/kwalify/messages_rb.html +2 -2
  17. data/doc-api/files/kwalify/meta-validator_rb.html +1 -1
  18. data/doc-api/files/kwalify/parser/base_rb.html +1 -1
  19. data/doc-api/files/kwalify/parser/yaml_rb.html +2 -2
  20. data/doc-api/files/kwalify/rule_rb.html +1 -1
  21. data/doc-api/files/kwalify/types_rb.html +1 -1
  22. data/doc-api/files/kwalify/util/assert-text-equal_rb.html +1 -1
  23. data/doc-api/files/kwalify/util/hash-interface_rb.html +1 -1
  24. data/doc-api/files/kwalify/util/hashlike_rb.html +1 -1
  25. data/doc-api/files/kwalify/util/option-parser_rb.html +1 -1
  26. data/doc-api/files/kwalify/util/ordered-hash_rb.html +1 -1
  27. data/doc-api/files/kwalify/util/testcase-helper_rb.html +1 -1
  28. data/doc-api/files/kwalify/util_rb.html +1 -1
  29. data/doc-api/files/kwalify/validator_rb.html +2 -2
  30. data/doc-api/files/kwalify/yaml-parser_rb.html +1 -1
  31. data/doc-api/files/kwalify_rb.html +2 -2
  32. data/doc/users-guide.html +20 -15
  33. data/examples/address-book/address-book.schema.yaml +1 -1
  34. data/examples/invoice/invoice.schema.yaml +1 -1
  35. data/examples/tapkit/tapkit.schema.yaml +1 -1
  36. data/lib/kwalify.rb +22 -12
  37. data/lib/kwalify/errors.rb +3 -3
  38. data/lib/kwalify/main.rb +1 -1
  39. data/lib/kwalify/messages.rb +1 -1
  40. data/lib/kwalify/meta-validator.rb +1 -1
  41. data/lib/kwalify/parser/base.rb +1 -1
  42. data/lib/kwalify/parser/yaml.rb +7 -3
  43. data/lib/kwalify/rule.rb +1 -1
  44. data/lib/kwalify/templates/genclass-java.eruby +1 -1
  45. data/lib/kwalify/templates/genclass-php.eruby +1 -1
  46. data/lib/kwalify/templates/genclass-ruby.eruby +1 -1
  47. data/lib/kwalify/types.rb +1 -1
  48. data/lib/kwalify/util.rb +1 -1
  49. data/lib/kwalify/util/assert-text-equal.rb +1 -1
  50. data/lib/kwalify/util/hash-interface.rb +1 -1
  51. data/lib/kwalify/util/hashlike.rb +1 -1
  52. data/lib/kwalify/util/option-parser.rb +1 -1
  53. data/lib/kwalify/util/ordered-hash.rb +1 -1
  54. data/lib/kwalify/util/testcase-helper.rb +1 -1
  55. data/lib/kwalify/validator.rb +5 -2
  56. data/lib/kwalify/yaml-parser.rb +1 -1
  57. data/test/data/users-guide/answers-validator.rb +9 -9
  58. data/test/data/users-guide/howto-validation.rb +2 -2
  59. data/test/data/users-guide/invalid07.result +1 -1
  60. data/test/data/users-guide/loadconfig.rb +2 -1
  61. data/test/data/users-guide/loadconfig.result +5 -1
  62. data/test/test-action.rb +1 -1
  63. data/test/test-action.yaml +1 -1
  64. data/test/test-databinding.rb +6 -3
  65. data/test/test-databinding.yaml +39 -1
  66. data/test/test-main.rb +1 -1
  67. data/test/test-main.yaml +1 -1
  68. data/test/test-metavalidator.rb +1 -1
  69. data/test/test-metavalidator.yaml +1 -1
  70. data/test/test-parser-yaml.rb +1 -1
  71. data/test/test-parser-yaml.yaml +1 -1
  72. data/test/test-rule.rb +1 -1
  73. data/test/test-rule.yaml +1 -1
  74. data/test/test-validator.rb +1 -1
  75. data/test/test-validator.yaml +1 -1
  76. data/test/test-yaml-parser.rb +1 -1
  77. data/test/test-yaml-parser.yaml +1 -1
  78. data/test/test.rb +1 -1
  79. metadata +2 -2
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 95 $
3
- ### $Release: 0.7.0 $
3
+ ### $Release: 0.7.1 $
4
4
  ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 95 $
3
- ### $Release: 0.7.0 $
3
+ ### $Release: 0.7.1 $
4
4
  ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 95 $
3
- ### $Release: 0.7.0 $
3
+ ### $Release: 0.7.1 $
4
4
  ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 92 $
3
- ### $Release: 0.7.0 $
3
+ ### $Release: 0.7.1 $
4
4
  ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
- ### $Rev: 93 $
3
- ### $Release: 0.7.0 $
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
- raise _syntax_error("mapping key is duplicated.", path)
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
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 95 $
3
- ### $Release: 0.7.0 $
3
+ ### $Release: 0.7.1 $
4
4
  ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  ###
4
4
  ### $Rev: 95 $
5
- ### $Release: 0.7.0 $
5
+ ### $Release: 0.7.1 $
6
6
  ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
7
7
  ###
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  ###
4
4
  ### $Rev$
5
- ### $Release: 0.7.0 $
5
+ ### $Release: 0.7.1 $
6
6
  ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
7
7
  ###
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  ###
4
4
  ### $Rev: 96 $
5
- ### $Release: 0.7.0 $
5
+ ### $Release: 0.7.1 $
6
6
  ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
7
7
  ###
8
8
 
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 87 $
3
- ### $Release: 0.7.0 $
3
+ ### $Release: 0.7.1 $
4
4
  ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 88 $
3
- ### $Release: 0.7.0 $
3
+ ### $Release: 0.7.1 $
4
4
  ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 83 $
3
- ### $Release: 0.7.0 $
3
+ ### $Release: 0.7.1 $
4
4
  ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 88 $$
3
- ### $Release: 0.7.0 $
3
+ ### $Release: 0.7.1 $
4
4
  ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 89 $
3
- ### $Release: 0.7.0 $
3
+ ### $Release: 0.7.1 $
4
4
  ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 83 $
3
- ### $Release: 0.7.0 $
3
+ ### $Release: 0.7.1 $
4
4
  ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 84 $
3
- ### 0.7.0
3
+ ### 0.7.1
4
4
  ### $COPYRIGHT$
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 83 $
3
- ### $Release: 0.7.0 $
3
+ ### $Release: 0.7.1 $
4
4
  ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ###
2
- ### $Rev: 89 $
3
- ### $Release: 0.7.0 $
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
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 81 $
3
- ### $Release: 0.7.0 $
3
+ ### $Release: 0.7.1 $
4
4
  ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -34,19 +34,19 @@ end
34
34
  ## create validator
35
35
  validator = AnswersValidator.new
36
36
 
37
- ## load YAML document
37
+ ## parse and validate YAML document
38
38
  input = ARGF.read()
39
- document = Kwalify::Yaml.load(input)
40
- ## or document = YAML.load(input)
39
+ parser = Kwalify::Yaml::Parser.new(validator)
40
+ document = parser.parse(input)
41
41
 
42
- ## validate
43
- errors = validator.validate(document)
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
- errors.each do |error|
49
- # error.class == Kwalify::ValidationError
50
- puts " - [#{error.path}] : #{error.message}"
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
@@ -19,7 +19,7 @@ errors = validator.validate(document)
19
19
 
20
20
  ## show errors
21
21
  if errors && !errors.empty?
22
- for err in errors
23
- puts "[#{err.path}] #{err.message}"
22
+ for e in errors
23
+ puts "[#{e.path}] #{e.message}"
24
24
  end
25
25
  end
@@ -1,3 +1,3 @@
1
1
  $ ruby answers-validator.rb document07b.yaml
2
2
  *** INVALID!
3
- - [/answers/1] : reason is required when answer is 'bad'.
3
+ 4:3 [/answers/1] reason is required when answer is 'bad'.
@@ -12,4 +12,5 @@ validator = Kwalify::Validator.new(schema)
12
12
  parser = Kwalify::Yaml::Parser.new(validator)
13
13
  parser.data_binding = true # enable data binding
14
14
  config = parser.parse_file('config.yaml')
15
- p config
15
+ require 'pp'
16
+ pp config
@@ -1,2 +1,6 @@
1
1
  $ ruby loadconfig.rb
2
- #<Config:0x542590 @host="localhost", @pass="password1", @port=8080, @user="user1">
2
+ #<Config:
3
+ @host="localhost",
4
+ @pass="password1",
5
+ @port=8080,
6
+ @user="user1">
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 90 $
3
- ### $Release: 0.7.0 $
3
+ ### $Release: 0.7.1 $
4
4
  ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 95 $
3
- ## $Release: 0.7.0 $
3
+ ## $Release: 0.7.1 $
4
4
  ## copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ##
6
6
  ---
@@ -1,6 +1,6 @@
1
1
  ###
2
- ### $Rev: 93 $
3
- ### $Release: 0.7.0 $
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
- eval @classdef if @classdef
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 ||= {}
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 63 $
3
- ## $Release: 0.7.0 $
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:
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 90 $
3
- ### $Release: 0.7.0 $
3
+ ### $Release: 0.7.1 $
4
4
  ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 93 $
3
- ## $Release: 0.7.0 $
3
+ ## $Release: 0.7.1 $
4
4
  ## copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ##
6
6
  ---
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 83 $
3
- ### $Release: 0.7.0 $
3
+ ### $Release: 0.7.1 $
4
4
  ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 95 $
3
- ## $Release: 0.7.0 $
3
+ ## $Release: 0.7.1 $
4
4
  ## copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ##
6
6
  ---
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 84 $
3
- ### $Release: 0.7.0 $
3
+ ### $Release: 0.7.1 $
4
4
  ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 59 $
3
- ## $Release: 0.7.0 $
3
+ ## $Release: 0.7.1 $
4
4
  ## copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ##
6
6
  ---
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 83 $
3
- ### $Release: 0.7.0 $
3
+ ### $Release: 0.7.1 $
4
4
  ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 95 $
3
- ## $Release: 0.7.0 $
3
+ ## $Release: 0.7.1 $
4
4
  ## copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ##
6
6
  ---
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 83 $
3
- ### $Release: 0.7.0 $
3
+ ### $Release: 0.7.1 $
4
4
  ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  ## $Rev: 83 $
3
- ## $Release: 0.7.0 $
3
+ ## $Release: 0.7.1 $
4
4
  ## copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ##
6
6
  ---
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### $Rev: 83 $
3
- ### $Release: 0.7.0 $
3
+ ### $Release: 0.7.1 $
4
4
  ### copyright(c) 2005-2008 kuwata-lab all rights reserved.
5
5
  ###
6
6