kwalify 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. data/CHANGES.txt +232 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.txt +16 -19
  4. data/bin/kwalify +3 -3
  5. data/contrib/inline-require +6 -4
  6. data/contrib/kwalify +3719 -2427
  7. data/doc-api/classes/CommandOptionError.html +17 -17
  8. data/doc-api/classes/CommandOptionParser.html +63 -63
  9. data/doc-api/classes/Kwalify.html +29 -7
  10. data/doc-api/classes/Kwalify/AssertionError.html +9 -9
  11. data/doc-api/classes/Kwalify/BaseError.html +72 -71
  12. data/doc-api/classes/Kwalify/BaseParser.html +461 -0
  13. data/doc-api/classes/Kwalify/CommandOptionError.html +11 -11
  14. data/doc-api/classes/Kwalify/ErrorHelper.html +51 -46
  15. data/doc-api/classes/Kwalify/HashInterface.html +13 -135
  16. data/doc-api/classes/Kwalify/Json.html +105 -0
  17. data/doc-api/classes/Kwalify/Main.html +129 -126
  18. data/doc-api/classes/Kwalify/MetaValidator.html +248 -232
  19. data/doc-api/classes/Kwalify/Parser.html +12 -12
  20. data/doc-api/classes/Kwalify/PlainYamlParser.html +166 -163
  21. data/doc-api/classes/Kwalify/PlainYamlParser/Alias.html +11 -11
  22. data/doc-api/classes/Kwalify/Rule.html +152 -130
  23. data/doc-api/classes/Kwalify/SchemaError.html +10 -10
  24. data/doc-api/classes/Kwalify/SyntaxError.html +185 -0
  25. data/doc-api/classes/Kwalify/Types.html +26 -25
  26. data/doc-api/classes/Kwalify/Util.html +389 -0
  27. data/doc-api/classes/Kwalify/Util/HashLike.html +246 -0
  28. data/doc-api/classes/Kwalify/Util/OrderedHash.html +330 -0
  29. data/doc-api/classes/Kwalify/ValidationError.html +10 -10
  30. data/doc-api/classes/Kwalify/Validator.html +153 -86
  31. data/doc-api/classes/Kwalify/Yaml.html +181 -0
  32. data/doc-api/classes/Kwalify/Yaml/Parser.html +1538 -0
  33. data/doc-api/classes/Kwalify/YamlParser.html +190 -183
  34. data/doc-api/classes/Kwalify/YamlSyntaxError.html +8 -57
  35. data/doc-api/created.rid +1 -1
  36. data/doc-api/files/__/README_txt.html +17 -22
  37. data/doc-api/files/kwalify/errors_rb.html +2 -2
  38. data/doc-api/files/kwalify/main_rb.html +4 -3
  39. data/doc-api/files/kwalify/messages_rb.html +2 -2
  40. data/doc-api/files/kwalify/meta-validator_rb.html +3 -3
  41. data/doc-api/files/kwalify/{util/yaml-helper_rb.html → parser/base_rb.html} +8 -6
  42. data/doc-api/files/kwalify/parser/yaml_rb.html +117 -0
  43. data/doc-api/files/kwalify/rule_rb.html +2 -2
  44. data/doc-api/files/kwalify/types_rb.html +2 -2
  45. data/doc-api/files/kwalify/util/assert-text-equal_rb.html +2 -2
  46. data/doc-api/files/kwalify/util/hash-interface_rb.html +9 -2
  47. data/doc-api/files/kwalify/util/hashlike_rb.html +107 -0
  48. data/doc-api/files/kwalify/util/option-parser_rb.html +2 -2
  49. data/doc-api/files/kwalify/util/ordered-hash_rb.html +107 -0
  50. data/doc-api/files/kwalify/util/testcase-helper_rb.html +2 -2
  51. data/doc-api/files/kwalify/util_rb.html +107 -0
  52. data/doc-api/files/kwalify/validator_rb.html +2 -2
  53. data/doc-api/files/kwalify/yaml-parser_rb.html +2 -2
  54. data/doc-api/files/kwalify_rb.html +3 -2
  55. data/doc-api/fr_class_index.html +8 -1
  56. data/doc-api/fr_file_index.html +5 -1
  57. data/doc-api/fr_method_index.html +128 -69
  58. data/doc/img/fig01.png +0 -0
  59. data/doc/users-guide.html +882 -717
  60. data/examples/address-book/address-book.schema.yaml +2 -2
  61. data/examples/data-binding/BABEL.data.yaml +63 -0
  62. data/examples/data-binding/BABEL.schema.yaml +31 -0
  63. data/examples/data-binding/Makefile +8 -0
  64. data/examples/data-binding/Rakefile +13 -0
  65. data/examples/data-binding/main.rb +27 -0
  66. data/examples/invoice/invoice.schema.yaml +3 -3
  67. data/examples/tapkit/tapkit.schema.yaml +2 -2
  68. data/lib/kwalify.rb +41 -4
  69. data/lib/kwalify/errors.rb +118 -96
  70. data/lib/kwalify/kwalify.schema.yaml +58 -0
  71. data/lib/kwalify/main.rb +384 -377
  72. data/lib/kwalify/messages.rb +41 -27
  73. data/lib/kwalify/meta-validator.rb +251 -331
  74. data/lib/kwalify/parser/base.rb +127 -0
  75. data/lib/kwalify/parser/yaml.rb +837 -0
  76. data/lib/kwalify/rule.rb +545 -487
  77. data/lib/kwalify/templates/genclass-java.eruby +189 -162
  78. data/lib/kwalify/templates/genclass-php.eruby +104 -0
  79. data/lib/kwalify/templates/genclass-ruby.eruby +95 -66
  80. data/lib/kwalify/types.rb +107 -106
  81. data/lib/kwalify/util.rb +157 -0
  82. data/lib/kwalify/util/assert-text-equal.rb +33 -31
  83. data/lib/kwalify/util/hash-interface.rb +11 -30
  84. data/lib/kwalify/util/hashlike.rb +51 -0
  85. data/lib/kwalify/util/option-parser.rb +144 -144
  86. data/lib/kwalify/util/ordered-hash.rb +57 -0
  87. data/lib/kwalify/util/testcase-helper.rb +3 -3
  88. data/lib/kwalify/validator.rb +267 -212
  89. data/lib/kwalify/yaml-parser.rb +822 -768
  90. data/setup.rb +861 -607
  91. data/test/Rookbook.yaml +10 -0
  92. data/test/{tmp.dir/Context.java → data/users-guide/AddressBook.java.expected} +11 -11
  93. data/test/data/users-guide/BABEL.data.yaml +24 -0
  94. data/test/data/users-guide/BABEL.schema.yaml +30 -0
  95. data/test/data/users-guide/ExampleAddressBook.java +47 -0
  96. data/test/{tmp.dir/Group.java → data/users-guide/Group.java.expected} +2 -11
  97. data/test/data/users-guide/Person.java.expected +44 -0
  98. data/test/data/users-guide/address_book.rb +52 -0
  99. data/test/data/users-guide/address_book.schema.yaml +28 -0
  100. data/test/data/users-guide/address_book.yaml +27 -0
  101. data/test/data/users-guide/answers-schema.yaml +12 -0
  102. data/test/data/users-guide/answers-validator.rb +52 -0
  103. data/test/data/users-guide/babel_genclass.result +26 -0
  104. data/test/data/users-guide/config.schema.yaml +7 -0
  105. data/test/data/users-guide/config.yaml +4 -0
  106. data/test/{tmp.dir/silent1.document → data/users-guide/document01a.yaml} +0 -0
  107. data/test/data/users-guide/document01b.yaml +3 -0
  108. data/test/data/users-guide/document02a.yaml +4 -0
  109. data/test/data/users-guide/document02b.yaml +4 -0
  110. data/test/data/users-guide/document03a.yaml +6 -0
  111. data/test/data/users-guide/document03b.yaml +6 -0
  112. data/test/data/users-guide/document04a.yaml +9 -0
  113. data/test/data/users-guide/document04b.yaml +9 -0
  114. data/test/data/users-guide/document05a.yaml +11 -0
  115. data/test/data/users-guide/document05b.yaml +12 -0
  116. data/test/data/users-guide/document06a.yaml +15 -0
  117. data/test/data/users-guide/document06b.yaml +16 -0
  118. data/test/data/users-guide/document07a.yaml +9 -0
  119. data/test/data/users-guide/document07b.yaml +7 -0
  120. data/test/data/users-guide/document12a.json +10 -0
  121. data/test/data/users-guide/document12b.json +6 -0
  122. data/test/data/users-guide/document13a.yaml +17 -0
  123. data/test/data/users-guide/document14a.yaml +3 -0
  124. data/test/data/users-guide/document14b.yaml +3 -0
  125. data/test/data/users-guide/document15a.yaml +6 -0
  126. data/test/data/users-guide/document15b.yaml +5 -0
  127. data/test/data/users-guide/example_address_book.rb +10 -0
  128. data/test/data/users-guide/example_address_book_java.result +32 -0
  129. data/test/data/users-guide/example_address_book_ruby.result +31 -0
  130. data/test/data/users-guide/genclass_java.result +4 -0
  131. data/test/data/users-guide/howto-validation-with-parsing.rb +28 -0
  132. data/test/data/users-guide/howto-validation.rb +25 -0
  133. data/test/data/users-guide/howto3.rb +6 -0
  134. data/test/data/users-guide/howto3.result +5 -0
  135. data/test/data/users-guide/howto3.yaml +8 -0
  136. data/test/data/users-guide/howto5_databinding.result +111 -0
  137. data/test/data/users-guide/invalid01.result +3 -0
  138. data/test/data/users-guide/invalid02.result +5 -0
  139. data/test/data/users-guide/invalid03.result +5 -0
  140. data/test/data/users-guide/invalid04.result +4 -0
  141. data/test/data/users-guide/invalid05.result +11 -0
  142. data/test/data/users-guide/invalid06.result +4 -0
  143. data/test/data/users-guide/invalid07.result +3 -0
  144. data/test/data/users-guide/invalid08.result +3 -0
  145. data/test/data/users-guide/invalid12.json +8 -0
  146. data/test/data/users-guide/invalid14.result +4 -0
  147. data/test/data/users-guide/invalid15.result +4 -0
  148. data/test/data/users-guide/loadbabel.rb +27 -0
  149. data/test/data/users-guide/loadconfig.rb +15 -0
  150. data/test/data/users-guide/loadconfig.result +2 -0
  151. data/test/data/users-guide/models.rb +22 -0
  152. data/test/data/users-guide/option_ha.result +6 -0
  153. data/test/data/users-guide/option_ha_genclass_java.result +7 -0
  154. data/test/{tmp.dir/meta1.schema → data/users-guide/schema01.yaml} +0 -0
  155. data/test/data/users-guide/schema02.yaml +12 -0
  156. data/test/data/users-guide/schema03.yaml +9 -0
  157. data/test/data/users-guide/schema04.yaml +20 -0
  158. data/test/data/users-guide/schema05.yaml +29 -0
  159. data/test/data/users-guide/schema06.yaml +11 -0
  160. data/test/data/users-guide/schema12.json +12 -0
  161. data/test/data/users-guide/schema13.yaml +13 -0
  162. data/test/data/users-guide/schema14.yaml +5 -0
  163. data/test/data/users-guide/schema15.yaml +21 -0
  164. data/test/data/users-guide/valid01.result +2 -0
  165. data/test/data/users-guide/valid02.result +2 -0
  166. data/test/data/users-guide/valid03.result +2 -0
  167. data/test/data/users-guide/valid04.result +2 -0
  168. data/test/data/users-guide/valid05.result +2 -0
  169. data/test/data/users-guide/valid06.result +2 -0
  170. data/test/data/users-guide/valid07.result +2 -0
  171. data/test/data/users-guide/valid08.result +2 -0
  172. data/test/data/users-guide/valid12.result +2 -0
  173. data/test/data/users-guide/valid13.result +2 -0
  174. data/test/data/users-guide/valid14.result +2 -0
  175. data/test/data/users-guide/valid15.result +2 -0
  176. data/test/data/users-guide/validate08.rb +37 -0
  177. data/test/test-action.rb +78 -0
  178. data/test/test-action.yaml +738 -0
  179. data/test/test-databinding.rb +80 -0
  180. data/test/test-databinding.yaml +301 -0
  181. data/test/test-main.rb +129 -150
  182. data/test/test-main.yaml +126 -321
  183. data/test/test-metavalidator.rb +47 -47
  184. data/test/test-metavalidator.yaml +77 -21
  185. data/test/test-parser-yaml.rb +57 -0
  186. data/test/test-parser-yaml.yaml +1749 -0
  187. data/test/test-rule.rb +14 -15
  188. data/test/test-rule.yaml +6 -3
  189. data/test/test-users-guide.rb +75 -0
  190. data/test/test-validator.rb +77 -52
  191. data/test/test-validator.yaml +168 -6
  192. data/test/test-yaml-parser.rb +47 -0
  193. data/test/{test-yamlparser.yaml → test-yaml-parser.yaml} +159 -52
  194. data/test/test.rb +37 -21
  195. metadata +136 -37
  196. data/COPYING +0 -340
  197. data/ChangeLog +0 -70
  198. data/doc-api/classes/YamlHelper.html +0 -259
  199. data/lib/kwalify/util/yaml-helper.rb +0 -82
  200. data/test/test-yamlparser.rb +0 -58
  201. data/test/tmp.dir/User.java +0 -43
  202. data/test/tmp.dir/action1.document +0 -18
  203. data/test/tmp.dir/action1.schema +0 -32
  204. data/test/tmp.dir/action2.document +0 -18
  205. data/test/tmp.dir/action2.schema +0 -32
  206. data/test/tmp.dir/emacs.document +0 -6
  207. data/test/tmp.dir/emacs.schema +0 -6
  208. data/test/tmp.dir/meta1.document +0 -0
  209. data/test/tmp.dir/meta2.document +0 -0
  210. data/test/tmp.dir/meta2.schema +0 -3
  211. data/test/tmp.dir/silent1.schema +0 -3
  212. data/test/tmp.dir/silent2.document +0 -7
  213. data/test/tmp.dir/silent2.schema +0 -3
  214. data/test/tmp.dir/stream.invalid +0 -8
  215. data/test/tmp.dir/stream.schema +0 -3
  216. data/test/tmp.dir/stream.valid +0 -8
  217. data/test/tmp.dir/untabify.document +0 -5
  218. data/test/tmp.dir/untabify.schema +0 -10
  219. data/todo.txt +0 -34
@@ -136,9 +136,9 @@
136
136
  <div class="method-source-code" id="M000010-source">
137
137
  <pre>
138
138
  <span class="ruby-comment cmt"># File kwalify/types.rb, line 119</span>
139
- <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">get_type_class</span>(<span class="ruby-identifier">type</span>)
140
- <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">type_class</span>(<span class="ruby-identifier">type</span>)
141
- <span class="ruby-keyword kw">end</span>
139
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">get_type_class</span>(<span class="ruby-identifier">type</span>)
140
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">type_class</span>(<span class="ruby-identifier">type</span>)
141
+ <span class="ruby-keyword kw">end</span>
142
142
  </pre>
143
143
  </div>
144
144
  </div>
@@ -159,11 +159,11 @@
159
159
  <div class="method-source-code" id="M000009-source">
160
160
  <pre>
161
161
  <span class="ruby-comment cmt"># File kwalify/types.rb, line 113</span>
162
- <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">type_class</span>(<span class="ruby-identifier">type</span>)
163
- <span class="ruby-identifier">klass</span> = <span class="ruby-ivar">@@type_table</span>[<span class="ruby-identifier">type</span>]
164
- <span class="ruby-comment cmt">#assert_error('type=#{type.inspect}') unless klass</span>
165
- <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">klass</span>
166
- <span class="ruby-keyword kw">end</span>
162
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">type_class</span>(<span class="ruby-identifier">type</span>)
163
+ <span class="ruby-identifier">klass</span> = <span class="ruby-ivar">@@type_table</span>[<span class="ruby-identifier">type</span>]
164
+ <span class="ruby-comment cmt">#assert_error('type=#{type.inspect}') unless klass</span>
165
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">klass</span>
166
+ <span class="ruby-keyword kw">end</span>
167
167
  </pre>
168
168
  </div>
169
169
  </div>
@@ -184,9 +184,9 @@
184
184
  <div class="method-source-code" id="M000008-source">
185
185
  <pre>
186
186
  <span class="ruby-comment cmt"># File kwalify/types.rb, line 109</span>
187
- <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">type_table</span>
188
- <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@@type_table</span>
189
- <span class="ruby-keyword kw">end</span>
187
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">type_table</span>
188
+ <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@@type_table</span>
189
+ <span class="ruby-keyword kw">end</span>
190
190
  </pre>
191
191
  </div>
192
192
  </div>
@@ -209,9 +209,9 @@
209
209
  <div class="method-source-code" id="M000011-source">
210
210
  <pre>
211
211
  <span class="ruby-comment cmt"># File kwalify/types.rb, line 134</span>
212
- <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">collection?</span>(<span class="ruby-identifier">val</span>)
213
- <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
214
- <span class="ruby-keyword kw">end</span>
212
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">collection?</span>(<span class="ruby-identifier">val</span>)
213
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
214
+ <span class="ruby-keyword kw">end</span>
215
215
  </pre>
216
216
  </div>
217
217
  </div>
@@ -231,10 +231,10 @@
231
231
  onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
232
232
  <div class="method-source-code" id="M000013-source">
233
233
  <pre>
234
- <span class="ruby-comment cmt"># File kwalify/types.rb, line 142</span>
235
- <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">collection_type?</span>(<span class="ruby-identifier">type</span>)
236
- <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">type</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'seq'</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">type</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'map'</span>
237
- <span class="ruby-keyword kw">end</span>
234
+ <span class="ruby-comment cmt"># File kwalify/types.rb, line 143</span>
235
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">collection_type?</span>(<span class="ruby-identifier">type</span>)
236
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">type</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'seq'</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">type</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'map'</span>
237
+ <span class="ruby-keyword kw">end</span>
238
238
  </pre>
239
239
  </div>
240
240
  </div>
@@ -255,9 +255,10 @@
255
255
  <div class="method-source-code" id="M000012-source">
256
256
  <pre>
257
257
  <span class="ruby-comment cmt"># File kwalify/types.rb, line 138</span>
258
- <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">scalar?</span>(<span class="ruby-identifier">val</span>)
259
- <span class="ruby-keyword kw">return</span> <span class="ruby-operator">!</span><span class="ruby-identifier">val</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">val</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">!=</span> <span class="ruby-constant">Object</span>
260
- <span class="ruby-keyword kw">end</span>
258
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">scalar?</span>(<span class="ruby-identifier">val</span>)
259
+ <span class="ruby-comment cmt">#return !val.is_a?(Array) &amp;&amp; !val.is_a?(Hash) &amp;&amp; val.class != Object</span>
260
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Kwalify</span><span class="ruby-operator">::</span><span class="ruby-constant">Scalar</span>) <span class="ruby-comment cmt">#&amp;&amp; val.class != Object</span>
261
+ <span class="ruby-keyword kw">end</span>
261
262
  </pre>
262
263
  </div>
263
264
  </div>
@@ -277,10 +278,10 @@
277
278
  onclick="toggleCode('M000014-source');return false;">[Source]</a></p>
278
279
  <div class="method-source-code" id="M000014-source">
279
280
  <pre>
280
- <span class="ruby-comment cmt"># File kwalify/types.rb, line 146</span>
281
- <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">scalar_type?</span>(<span class="ruby-identifier">type</span>)
282
- <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">type</span> <span class="ruby-operator">!=</span> <span class="ruby-value str">'seq'</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">type</span> <span class="ruby-operator">!=</span> <span class="ruby-value str">'map'</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">type</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'any'</span>
283
- <span class="ruby-keyword kw">end</span>
281
+ <span class="ruby-comment cmt"># File kwalify/types.rb, line 147</span>
282
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">scalar_type?</span>(<span class="ruby-identifier">type</span>)
283
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">type</span> <span class="ruby-operator">!=</span> <span class="ruby-value str">'seq'</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">type</span> <span class="ruby-operator">!=</span> <span class="ruby-value str">'map'</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">type</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'any'</span>
284
+ <span class="ruby-keyword kw">end</span>
284
285
  </pre>
285
286
  </div>
286
287
  </div>
@@ -0,0 +1,389 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Module: Kwalify::Util</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Module</strong></td>
53
+ <td class="class-name-in-header">Kwalify::Util</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../../files/kwalify/util/hashlike_rb.html">
59
+ kwalify/util/hashlike.rb
60
+ </a>
61
+ <br />
62
+ <a href="../../files/kwalify/util/ordered-hash_rb.html">
63
+ kwalify/util/ordered-hash.rb
64
+ </a>
65
+ <br />
66
+ <a href="../../files/kwalify/util_rb.html">
67
+ kwalify/util.rb
68
+ </a>
69
+ <br />
70
+ <a href="../../files/kwalify_rb.html">
71
+ kwalify.rb
72
+ </a>
73
+ <br />
74
+ </td>
75
+ </tr>
76
+
77
+ </table>
78
+ </div>
79
+ <!-- banner header -->
80
+
81
+ <div id="bodyContent">
82
+
83
+
84
+
85
+ <div id="contextContent">
86
+
87
+
88
+
89
+ </div>
90
+
91
+ <div id="method-list">
92
+ <h3 class="section-bar">Methods</h3>
93
+
94
+ <div class="name-list">
95
+ <a href="#M000023">create_hashtable</a>&nbsp;&nbsp;
96
+ <a href="#M000022">get_class</a>&nbsp;&nbsp;
97
+ <a href="#M000024">get_value</a>&nbsp;&nbsp;
98
+ <a href="#M000021">traverse_rule</a>&nbsp;&nbsp;
99
+ <a href="#M000020">traverse_schema</a>&nbsp;&nbsp;
100
+ <a href="#M000019">untabify</a>&nbsp;&nbsp;
101
+ </div>
102
+ </div>
103
+
104
+ </div>
105
+
106
+
107
+ <!-- if includes -->
108
+
109
+ <div id="section">
110
+
111
+ <div id="class-list">
112
+ <h3 class="section-bar">Classes and Modules</h3>
113
+
114
+ Module <a href="Util/HashLike.html" class="link">Kwalify::Util::HashLike</a><br />
115
+ Class <a href="Util/OrderedHash.html" class="link">Kwalify::Util::OrderedHash</a><br />
116
+
117
+ </div>
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+ <!-- if method_list -->
126
+ <div id="methods">
127
+ <h3 class="section-bar">Public Instance methods</h3>
128
+
129
+ <div id="method-M000023" class="method-detail">
130
+ <a name="M000023"></a>
131
+
132
+ <div class="method-heading">
133
+ <a href="#M000023" class="method-signature">
134
+ <span class="method-name">create_hashtable</span><span class="method-args">(hashlist, primarykey, flag_duplicate_check=true)</span>
135
+ </a>
136
+ </div>
137
+
138
+ <div class="method-description">
139
+ <p>
140
+ create a hash table from list of hash with primary key.
141
+ </p>
142
+ <p>
143
+ ex.
144
+ </p>
145
+ <pre>
146
+ hashlist = [
147
+ { &quot;name&quot;=&gt;&quot;Foo&quot;, &quot;gender&quot;=&gt;&quot;M&quot;, &quot;age&quot;=&gt;20, },
148
+ { &quot;name&quot;=&gt;&quot;Bar&quot;, &quot;gender&quot;=&gt;&quot;F&quot;, &quot;age&quot;=&gt;25, },
149
+ { &quot;name&quot;=&gt;&quot;Baz&quot;, &quot;gender&quot;=&gt;&quot;M&quot;, &quot;age&quot;=&gt;30, },
150
+ ]
151
+ hashtable = YamlHelper.create_hashtable(hashlist, &quot;name&quot;)
152
+ p hashtable
153
+ # =&gt; { &quot;Foo&quot; =&gt; { &quot;name&quot;=&gt;&quot;Foo&quot;, &quot;gender&quot;=&gt;&quot;M&quot;, &quot;age&quot;=&gt;20, },
154
+ # &quot;Bar&quot; =&gt; { &quot;name&quot;=&gt;&quot;Bar&quot;, &quot;gender&quot;=&gt;&quot;F&quot;, &quot;age&quot;=&gt;25, },
155
+ # &quot;Baz&quot; =&gt; { &quot;name&quot;=&gt;&quot;Baz&quot;, &quot;gender&quot;=&gt;&quot;M&quot;, &quot;age&quot;=&gt;30, }, }
156
+ </pre>
157
+ <p><a class="source-toggle" href="#"
158
+ onclick="toggleCode('M000023-source');return false;">[Source]</a></p>
159
+ <div class="method-source-code" id="M000023-source">
160
+ <pre>
161
+ <span class="ruby-comment cmt"># File kwalify/util.rb, line 117</span>
162
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create_hashtable</span>(<span class="ruby-identifier">hashlist</span>, <span class="ruby-identifier">primarykey</span>, <span class="ruby-identifier">flag_duplicate_check</span>=<span class="ruby-keyword kw">true</span>)
163
+ <span class="ruby-identifier">hashtable</span> = {}
164
+ <span class="ruby-identifier">hashlist</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">hash</span><span class="ruby-operator">|</span>
165
+ <span class="ruby-identifier">key</span> = <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">primarykey</span>]
166
+ <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">key</span>
167
+ <span class="ruby-identifier">riase</span> <span class="ruby-node">&quot;primary key '#{key}' not found.&quot;</span>
168
+ <span class="ruby-keyword kw">end</span>
169
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">flag_duplicate_check</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">hashtable</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">key</span>)
170
+ <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;primary key '#{key}' duplicated (value '#{hashtable[key]}')&quot;</span>
171
+ <span class="ruby-keyword kw">end</span>
172
+ <span class="ruby-identifier">hashtable</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">hash</span>
173
+ <span class="ruby-keyword kw">end</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">hashlist</span>
174
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">hashtable</span>
175
+ <span class="ruby-keyword kw">end</span>
176
+ </pre>
177
+ </div>
178
+ </div>
179
+ </div>
180
+
181
+ <div id="method-M000022" class="method-detail">
182
+ <a name="M000022"></a>
183
+
184
+ <div class="method-heading">
185
+ <a href="#M000022" class="method-signature">
186
+ <span class="method-name">get_class</span><span class="method-args">(classname)</span>
187
+ </a>
188
+ </div>
189
+
190
+ <div class="method-description">
191
+ <p>
192
+ get class object. if not found, NameError raised.
193
+ </p>
194
+ <p><a class="source-toggle" href="#"
195
+ onclick="toggleCode('M000022-source');return false;">[Source]</a></p>
196
+ <div class="method-source-code" id="M000022-source">
197
+ <pre>
198
+ <span class="ruby-comment cmt"># File kwalify/util.rb, line 93</span>
199
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_class</span>(<span class="ruby-identifier">classname</span>)
200
+ <span class="ruby-identifier">klass</span> = <span class="ruby-constant">Object</span>
201
+ <span class="ruby-identifier">classname</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'::'</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">name</span><span class="ruby-operator">|</span>
202
+ <span class="ruby-identifier">klass</span> = <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-identifier">name</span>)
203
+ <span class="ruby-keyword kw">end</span>
204
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">klass</span>
205
+ <span class="ruby-keyword kw">end</span>
206
+ </pre>
207
+ </div>
208
+ </div>
209
+ </div>
210
+
211
+ <div id="method-M000024" class="method-detail">
212
+ <a name="M000024"></a>
213
+
214
+ <div class="method-heading">
215
+ <a href="#M000024" class="method-signature">
216
+ <span class="method-name">get_value</span><span class="method-args">(obj, path)</span>
217
+ </a>
218
+ </div>
219
+
220
+ <div class="method-description">
221
+ <p>
222
+ get nested value directly.
223
+ </p>
224
+ <p>
225
+ ex.
226
+ </p>
227
+ <pre>
228
+ val = YamlHelper.get_value(obj, ['aaa', 0, 'xxx'])
229
+ </pre>
230
+ <p>
231
+ This is equal to the following:
232
+ </p>
233
+ <pre>
234
+ begin
235
+ val = obj['aaa'][0]['xxx']
236
+ rescue NameError
237
+ val = nil
238
+ end
239
+ </pre>
240
+ <p><a class="source-toggle" href="#"
241
+ onclick="toggleCode('M000024-source');return false;">[Source]</a></p>
242
+ <div class="method-source-code" id="M000024-source">
243
+ <pre>
244
+ <span class="ruby-comment cmt"># File kwalify/util.rb, line 146</span>
245
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_value</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-identifier">path</span>)
246
+ <span class="ruby-identifier">val</span> = <span class="ruby-identifier">obj</span>
247
+ <span class="ruby-identifier">path</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span><span class="ruby-operator">|</span>
248
+ <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>)
249
+ <span class="ruby-identifier">val</span> = <span class="ruby-identifier">val</span>[<span class="ruby-identifier">key</span>]
250
+ <span class="ruby-keyword kw">end</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">path</span>
251
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">val</span>
252
+ <span class="ruby-keyword kw">end</span>
253
+ </pre>
254
+ </div>
255
+ </div>
256
+ </div>
257
+
258
+ <div id="method-M000021" class="method-detail">
259
+ <a name="M000021"></a>
260
+
261
+ <div class="method-heading">
262
+ <a href="#M000021" class="method-signature">
263
+ <span class="method-name">traverse_rule</span><span class="method-args">(validator) {|rule| ...}</span>
264
+ </a>
265
+ </div>
266
+
267
+ <div class="method-description">
268
+ <p>
269
+ traverse rule
270
+ </p>
271
+ <p>
272
+ ex.
273
+ </p>
274
+ <pre>
275
+ schema = YAML.load_file('myschema.yaml')
276
+ validator = Kwalify::Validator.new(schema)
277
+ Kwalify::Util.traverse_rule(validator) do |rule|
278
+ p rule if rule.classname
279
+ end
280
+ </pre>
281
+ <p><a class="source-toggle" href="#"
282
+ onclick="toggleCode('M000021-source');return false;">[Source]</a></p>
283
+ <div class="method-source-code" id="M000021-source">
284
+ <pre>
285
+ <span class="ruby-comment cmt"># File kwalify/util.rb, line 70</span>
286
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">traverse_rule</span>(<span class="ruby-identifier">validator</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>) <span class="ruby-comment cmt">#:yield: rule</span>
287
+ <span class="ruby-identifier">rule</span> = <span class="ruby-identifier">validator</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Rule</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">validator</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">validator</span>.<span class="ruby-identifier">rule</span>
288
+ <span class="ruby-identifier">_done</span> = {}
289
+ <span class="ruby-identifier">_traverse_rule</span>(<span class="ruby-identifier">rule</span>, <span class="ruby-identifier">_done</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
290
+ <span class="ruby-keyword kw">end</span>
291
+ </pre>
292
+ </div>
293
+ </div>
294
+ </div>
295
+
296
+ <div id="method-M000020" class="method-detail">
297
+ <a name="M000020"></a>
298
+
299
+ <div class="method-heading">
300
+ <a href="#M000020" class="method-signature">
301
+ <span class="method-name">traverse_schema</span><span class="method-args">(schema) {|rulehash| ...}</span>
302
+ </a>
303
+ </div>
304
+
305
+ <div class="method-description">
306
+ <p>
307
+ traverse schema
308
+ </p>
309
+ <p>
310
+ ex.
311
+ </p>
312
+ <pre>
313
+ schema = YAML.load_file('myschema.yaml')
314
+ Kwalify::Util.traverse_schema(schema) do |rulehash|
315
+ ## add module prefix to class name
316
+ if rulehash['class']
317
+ rulehash['class'] = &quot;MyModule::' + rulehash['class']
318
+ end
319
+ end
320
+ </pre>
321
+ <p><a class="source-toggle" href="#"
322
+ onclick="toggleCode('M000020-source');return false;">[Source]</a></p>
323
+ <div class="method-source-code" id="M000020-source">
324
+ <pre>
325
+ <span class="ruby-comment cmt"># File kwalify/util.rb, line 43</span>
326
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">traverse_schema</span>(<span class="ruby-identifier">schema</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>) <span class="ruby-comment cmt">#:yield: rulehash</span>
327
+ <span class="ruby-identifier">hash</span> = <span class="ruby-identifier">schema</span>
328
+ <span class="ruby-identifier">_done</span> = {}
329
+ <span class="ruby-identifier">_traverse_schema</span>(<span class="ruby-identifier">hash</span>, <span class="ruby-identifier">_done</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
330
+ <span class="ruby-keyword kw">end</span>
331
+ </pre>
332
+ </div>
333
+ </div>
334
+ </div>
335
+
336
+ <div id="method-M000019" class="method-detail">
337
+ <a name="M000019"></a>
338
+
339
+ <div class="method-heading">
340
+ <a href="#M000019" class="method-signature">
341
+ <span class="method-name">untabify</span><span class="method-args">(str, width=8)</span>
342
+ </a>
343
+ </div>
344
+
345
+ <div class="method-description">
346
+ <p>
347
+ expand tab character to spaces
348
+ </p>
349
+ <p>
350
+ ex.
351
+ </p>
352
+ <pre>
353
+ untabified_str = YamlHelper.untabify(tabbed_str)
354
+ </pre>
355
+ <p><a class="source-toggle" href="#"
356
+ onclick="toggleCode('M000019-source');return false;">[Source]</a></p>
357
+ <div class="method-source-code" id="M000019-source">
358
+ <pre>
359
+ <span class="ruby-comment cmt"># File kwalify/util.rb, line 19</span>
360
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">untabify</span>(<span class="ruby-identifier">str</span>, <span class="ruby-identifier">width</span>=<span class="ruby-value">8</span>)
361
+ <span class="ruby-identifier">list</span> = <span class="ruby-identifier">str</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">/\t/</span>)
362
+ <span class="ruby-identifier">last</span> = <span class="ruby-identifier">list</span>.<span class="ruby-identifier">pop</span>
363
+ <span class="ruby-identifier">sb</span> = <span class="ruby-value str">''</span>
364
+ <span class="ruby-identifier">list</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span>
365
+ <span class="ruby-identifier">column</span> = (<span class="ruby-identifier">n</span> = <span class="ruby-identifier">s</span>.<span class="ruby-identifier">rindex</span>(<span class="ruby-value">?\n</span>)) <span class="ruby-operator">?</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">n</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">length</span>
366
+ <span class="ruby-identifier">n</span> = <span class="ruby-identifier">width</span> <span class="ruby-operator">-</span> (<span class="ruby-identifier">column</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">width</span>)
367
+ <span class="ruby-identifier">sb</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">s</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-value str">' '</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">n</span>)
368
+ <span class="ruby-keyword kw">end</span>
369
+ <span class="ruby-identifier">sb</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">last</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">last</span>
370
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">sb</span>
371
+ <span class="ruby-keyword kw">end</span>
372
+ </pre>
373
+ </div>
374
+ </div>
375
+ </div>
376
+
377
+
378
+ </div>
379
+
380
+
381
+ </div>
382
+
383
+
384
+ <div id="validator-badges">
385
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
386
+ </div>
387
+
388
+ </body>
389
+ </html>