schemacop 2.0.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -17
- data/.travis.yml +0 -2
- data/CHANGELOG.md +19 -0
- data/README.md +39 -6
- data/Rakefile +5 -1
- data/VERSION +1 -1
- data/doc/Schemacop.html +3 -3
- data/doc/Schemacop/ArrayValidator.html +1 -1
- data/doc/Schemacop/BooleanValidator.html +1 -1
- data/doc/Schemacop/Collector.html +1 -1
- data/doc/Schemacop/Exceptions.html +1 -1
- data/doc/Schemacop/Exceptions/InvalidSchemaError.html +1 -1
- data/doc/Schemacop/Exceptions/ValidationError.html +1 -1
- data/doc/Schemacop/FieldNode.html +1 -1
- data/doc/Schemacop/FloatValidator.html +1 -1
- data/doc/Schemacop/HashValidator.html +30 -4
- data/doc/Schemacop/IntegerValidator.html +1 -1
- data/doc/Schemacop/NilValidator.html +1 -1
- data/doc/Schemacop/Node.html +2 -2
- data/doc/Schemacop/NodeResolver.html +1 -1
- data/doc/Schemacop/NodeSupportingField.html +1 -1
- data/doc/Schemacop/NodeSupportingType.html +1 -1
- data/doc/Schemacop/NodeWithBlock.html +1 -1
- data/doc/Schemacop/NumberValidator.html +1 -1
- data/doc/Schemacop/ObjectValidator.html +1 -1
- data/doc/Schemacop/RootNode.html +1 -1
- data/doc/Schemacop/Schema.html +1 -1
- data/doc/Schemacop/StringValidator.html +1 -1
- data/doc/Schemacop/SymbolValidator.html +145 -0
- data/doc/ScopedEnv.html +1 -1
- data/doc/_index.html +8 -1
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +37 -7
- data/doc/index.html +37 -7
- data/doc/top-level-namespace.html +1 -1
- data/lib/schemacop.rb +2 -0
- data/lib/schemacop/node_supporting_field.rb +2 -4
- data/lib/schemacop/validator/hash_validator.rb +15 -2
- data/lib/schemacop/validator/symbol_validator.rb +5 -0
- data/schemacop.gemspec +8 -8
- data/test/types_test.rb +1 -0
- data/test/validator_symbol_test.rb +16 -0
- metadata +26 -16
data/doc/Schemacop/RootNode.html
CHANGED
@@ -161,7 +161,7 @@
|
|
161
161
|
</div>
|
162
162
|
|
163
163
|
<div id="footer">
|
164
|
-
Generated on
|
164
|
+
Generated on Wed May 17 10:53:58 2017 by
|
165
165
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
166
166
|
0.9.9 (ruby-2.3.1).
|
167
167
|
</div>
|
data/doc/Schemacop/Schema.html
CHANGED
@@ -687,7 +687,7 @@ this exception is thrown.</p>
|
|
687
687
|
</div>
|
688
688
|
|
689
689
|
<div id="footer">
|
690
|
-
Generated on
|
690
|
+
Generated on Wed May 17 10:53:58 2017 by
|
691
691
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
692
692
|
0.9.9 (ruby-2.3.1).
|
693
693
|
</div>
|
@@ -285,7 +285,7 @@
|
|
285
285
|
</div>
|
286
286
|
|
287
287
|
<div id="footer">
|
288
|
-
Generated on
|
288
|
+
Generated on Wed May 17 10:53:58 2017 by
|
289
289
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
290
290
|
0.9.9 (ruby-2.3.1).
|
291
291
|
</div>
|
@@ -0,0 +1,145 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
Class: Schemacop::SymbolValidator
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.9
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
pathId = "Schemacop::SymbolValidator";
|
19
|
+
relpath = '../';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="../class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="../_index.html">Index (S)</a> »
|
40
|
+
<span class='title'><span class='object_link'><a href="../Schemacop.html" title="Schemacop (module)">Schemacop</a></span></span>
|
41
|
+
»
|
42
|
+
<span class="title">SymbolValidator</span>
|
43
|
+
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div id="search">
|
47
|
+
|
48
|
+
<a class="full_list_link" id="class_list_link"
|
49
|
+
href="../class_list.html">
|
50
|
+
|
51
|
+
<svg width="24" height="24">
|
52
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
+
</svg>
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<div id="content"><h1>Class: Schemacop::SymbolValidator
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
<dl>
|
70
|
+
<dt>Inherits:</dt>
|
71
|
+
<dd>
|
72
|
+
<span class="inheritName"><span class='object_link'><a href="Node.html" title="Schemacop::Node (class)">Node</a></span></span>
|
73
|
+
|
74
|
+
<ul class="fullTree">
|
75
|
+
<li>Object</li>
|
76
|
+
|
77
|
+
<li class="next"><span class='object_link'><a href="Node.html" title="Schemacop::Node (class)">Node</a></span></li>
|
78
|
+
|
79
|
+
<li class="next">Schemacop::SymbolValidator</li>
|
80
|
+
|
81
|
+
</ul>
|
82
|
+
<a href="#" class="inheritanceTree">show all</a>
|
83
|
+
|
84
|
+
</dd>
|
85
|
+
</dl>
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
<dl>
|
98
|
+
<dt>Defined in:</dt>
|
99
|
+
<dd>lib/schemacop/validator/symbol_validator.rb</dd>
|
100
|
+
</dl>
|
101
|
+
|
102
|
+
</div>
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
<h2>Instance Attribute Summary</h2>
|
111
|
+
|
112
|
+
<h3 class="inherited">Attributes inherited from <span class='object_link'><a href="Node.html" title="Schemacop::Node (class)">Node</a></span></h3>
|
113
|
+
<p class="inherited"><span class='object_link'><a href="Node.html#options-instance_method" title="Schemacop::Node#options (method)">#options</a></span></p>
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
<h2>Method Summary</h2>
|
124
|
+
|
125
|
+
<h3 class="inherited">Methods inherited from <span class='object_link'><a href="Node.html" title="Schemacop::Node (class)">Node</a></span></h3>
|
126
|
+
<p class="inherited"><span class='object_link'><a href="Node.html#build-class_method" title="Schemacop::Node.build (method)">build</a></span>, <span class='object_link'><a href="Node.html#class_matches%3F-class_method" title="Schemacop::Node.class_matches? (method)">class_matches?</a></span>, <span class='object_link'><a href="Node.html#clear_klasses-class_method" title="Schemacop::Node.clear_klasses (method)">clear_klasses</a></span>, <span class='object_link'><a href="Node.html#clear_symbols-class_method" title="Schemacop::Node.clear_symbols (method)">clear_symbols</a></span>, <span class='object_link'><a href="Node.html#exec_block-instance_method" title="Schemacop::Node#exec_block (method)">#exec_block</a></span>, <span class='object_link'><a href="Node.html#initialize-instance_method" title="Schemacop::Node#initialize (method)">#initialize</a></span>, <span class='object_link'><a href="Node.html#klass-class_method" title="Schemacop::Node.klass (method)">klass</a></span>, <span class='object_link'><a href="Node.html#option-class_method" title="Schemacop::Node.option (method)">option</a></span>, <span class='object_link'><a href="Node.html#option-instance_method" title="Schemacop::Node#option (method)">#option</a></span>, <span class='object_link'><a href="Node.html#option%3F-instance_method" title="Schemacop::Node#option? (method)">#option?</a></span>, <span class='object_link'><a href="Node.html#register-class_method" title="Schemacop::Node.register (method)">register</a></span>, <span class='object_link'><a href="Node.html#resolve_type_klass-instance_method" title="Schemacop::Node#resolve_type_klass (method)">#resolve_type_klass</a></span>, <span class='object_link'><a href="Node.html#symbol-class_method" title="Schemacop::Node.symbol (method)">symbol</a></span>, <span class='object_link'><a href="Node.html#symbol_matches%3F-class_method" title="Schemacop::Node.symbol_matches? (method)">symbol_matches?</a></span>, <span class='object_link'><a href="Node.html#type_filter_matches%3F-instance_method" title="Schemacop::Node#type_filter_matches? (method)">#type_filter_matches?</a></span>, <span class='object_link'><a href="Node.html#type_label-instance_method" title="Schemacop::Node#type_label (method)">#type_label</a></span>, <span class='object_link'><a href="Node.html#type_matches%3F-class_method" title="Schemacop::Node.type_matches? (method)">type_matches?</a></span>, <span class='object_link'><a href="Node.html#type_matches%3F-instance_method" title="Schemacop::Node#type_matches? (method)">#type_matches?</a></span>, <span class='object_link'><a href="Node.html#validate-instance_method" title="Schemacop::Node#validate (method)">#validate</a></span></p>
|
127
|
+
<div id="constructor_details" class="method_details_list">
|
128
|
+
<h2>Constructor Details</h2>
|
129
|
+
|
130
|
+
<p class="notice">This class inherits a constructor from <span class='object_link'><a href="Node.html#initialize-instance_method" title="Schemacop::Node#initialize (method)">Schemacop::Node</a></span></p>
|
131
|
+
|
132
|
+
</div>
|
133
|
+
|
134
|
+
|
135
|
+
</div>
|
136
|
+
|
137
|
+
<div id="footer">
|
138
|
+
Generated on Wed May 17 10:53:58 2017 by
|
139
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
140
|
+
0.9.9 (ruby-2.3.1).
|
141
|
+
</div>
|
142
|
+
|
143
|
+
</div>
|
144
|
+
</body>
|
145
|
+
</html>
|
data/doc/ScopedEnv.html
CHANGED
@@ -341,7 +341,7 @@
|
|
341
341
|
</div>
|
342
342
|
|
343
343
|
<div id="footer">
|
344
|
-
Generated on
|
344
|
+
Generated on Wed May 17 10:53:58 2017 by
|
345
345
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
346
346
|
0.9.9 (ruby-2.3.1).
|
347
347
|
</div>
|
data/doc/_index.html
CHANGED
@@ -313,6 +313,13 @@
|
|
313
313
|
|
314
314
|
</li>
|
315
315
|
|
316
|
+
<li>
|
317
|
+
<span class='object_link'><a href="Schemacop/SymbolValidator.html" title="Schemacop::SymbolValidator (class)">SymbolValidator</a></span>
|
318
|
+
|
319
|
+
<small>(Schemacop)</small>
|
320
|
+
|
321
|
+
</li>
|
322
|
+
|
316
323
|
</ul>
|
317
324
|
</ul>
|
318
325
|
|
@@ -340,7 +347,7 @@
|
|
340
347
|
</div>
|
341
348
|
|
342
349
|
<div id="footer">
|
343
|
-
Generated on
|
350
|
+
Generated on Wed May 17 10:53:58 2017 by
|
344
351
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
345
352
|
0.9.9 (ruby-2.3.1).
|
346
353
|
</div>
|
data/doc/class_list.html
CHANGED
@@ -43,7 +43,7 @@
|
|
43
43
|
|
44
44
|
<ul id="full_list" class="class">
|
45
45
|
<li id="object_" class="odd"><div class="item" style="padding-left:30px"><span class='object_link'><a href="top-level-namespace.html" title="Top Level Namespace (root)">Top Level Namespace</a></span></div></li>
|
46
|
-
<li id='object_Schemacop' class='even'><div class='item' style='padding-left:30px'><a class='toggle'></a> <span class='object_link'><a href="Schemacop.html" title="Schemacop (module)">Schemacop</a></span><small class='search_info'>Top Level Namespace</small></div><ul><li id='object_Schemacop::ArrayValidator' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/ArrayValidator.html" title="Schemacop::ArrayValidator (class)">ArrayValidator</a></span> < NodeSupportingType<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::BooleanValidator' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/BooleanValidator.html" title="Schemacop::BooleanValidator (class)">BooleanValidator</a></span> < Node<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::Collector' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/Collector.html" title="Schemacop::Collector (class)">Collector</a></span> < Object<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::Exceptions' class='collapsed even'><div class='item' style='padding-left:45px'><a class='toggle'></a> <span class='object_link'><a href="Schemacop/Exceptions.html" title="Schemacop::Exceptions (module)">Exceptions</a></span><small class='search_info'>Schemacop</small></div><ul><li id='object_Schemacop::Exceptions::InvalidSchemaError' class='collapsed'><div class='item' style='padding-left:60px'><span class='object_link'><a href="Schemacop/Exceptions/InvalidSchemaError.html" title="Schemacop::Exceptions::InvalidSchemaError (class)">InvalidSchemaError</a></span> < RuntimeError<small class='search_info'>Schemacop::Exceptions</small></div></li><li id='object_Schemacop::Exceptions::ValidationError' class='collapsed'><div class='item' style='padding-left:60px'><span class='object_link'><a href="Schemacop/Exceptions/ValidationError.html" title="Schemacop::Exceptions::ValidationError (class)">ValidationError</a></span> < RuntimeError<small class='search_info'>Schemacop::Exceptions</small></div></li></ul></li><li id='object_Schemacop::FieldNode' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/FieldNode.html" title="Schemacop::FieldNode (class)">FieldNode</a></span> < NodeSupportingType<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::FloatValidator' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/FloatValidator.html" title="Schemacop::FloatValidator (class)">FloatValidator</a></span> < NumberValidator<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::HashValidator' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/HashValidator.html" title="Schemacop::HashValidator (class)">HashValidator</a></span> < NodeSupportingField<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::IntegerValidator' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/IntegerValidator.html" title="Schemacop::IntegerValidator (class)">IntegerValidator</a></span> < NumberValidator<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::NilValidator' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/NilValidator.html" title="Schemacop::NilValidator (class)">NilValidator</a></span> < Node<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::Node' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/Node.html" title="Schemacop::Node (class)">Node</a></span> < Object<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::NodeResolver' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/NodeResolver.html" title="Schemacop::NodeResolver (class)">NodeResolver</a></span> < Object<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::NodeSupportingField' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/NodeSupportingField.html" title="Schemacop::NodeSupportingField (class)">NodeSupportingField</a></span> < NodeWithBlock<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::NodeSupportingType' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/NodeSupportingType.html" title="Schemacop::NodeSupportingType (class)">NodeSupportingType</a></span> < NodeWithBlock<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::NodeWithBlock' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/NodeWithBlock.html" title="Schemacop::NodeWithBlock (class)">NodeWithBlock</a></span> < Node<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::NumberValidator' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/NumberValidator.html" title="Schemacop::NumberValidator (class)">NumberValidator</a></span> < Node<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::ObjectValidator' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/ObjectValidator.html" title="Schemacop::ObjectValidator (class)">ObjectValidator</a></span> < Node<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::RootNode' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/RootNode.html" title="Schemacop::RootNode (class)">RootNode</a></span> < NodeSupportingType<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::Schema' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/Schema.html" title="Schemacop::Schema (class)">Schema</a></span> < Object<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::StringValidator' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/StringValidator.html" title="Schemacop::StringValidator (class)">StringValidator</a></span> < Node<small class='search_info'>Schemacop</small></div></li></ul></li><li id='object_ScopedEnv' class='
|
46
|
+
<li id='object_Schemacop' class='even'><div class='item' style='padding-left:30px'><a class='toggle'></a> <span class='object_link'><a href="Schemacop.html" title="Schemacop (module)">Schemacop</a></span><small class='search_info'>Top Level Namespace</small></div><ul><li id='object_Schemacop::ArrayValidator' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/ArrayValidator.html" title="Schemacop::ArrayValidator (class)">ArrayValidator</a></span> < NodeSupportingType<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::BooleanValidator' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/BooleanValidator.html" title="Schemacop::BooleanValidator (class)">BooleanValidator</a></span> < Node<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::Collector' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/Collector.html" title="Schemacop::Collector (class)">Collector</a></span> < Object<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::Exceptions' class='collapsed even'><div class='item' style='padding-left:45px'><a class='toggle'></a> <span class='object_link'><a href="Schemacop/Exceptions.html" title="Schemacop::Exceptions (module)">Exceptions</a></span><small class='search_info'>Schemacop</small></div><ul><li id='object_Schemacop::Exceptions::InvalidSchemaError' class='collapsed'><div class='item' style='padding-left:60px'><span class='object_link'><a href="Schemacop/Exceptions/InvalidSchemaError.html" title="Schemacop::Exceptions::InvalidSchemaError (class)">InvalidSchemaError</a></span> < RuntimeError<small class='search_info'>Schemacop::Exceptions</small></div></li><li id='object_Schemacop::Exceptions::ValidationError' class='collapsed'><div class='item' style='padding-left:60px'><span class='object_link'><a href="Schemacop/Exceptions/ValidationError.html" title="Schemacop::Exceptions::ValidationError (class)">ValidationError</a></span> < RuntimeError<small class='search_info'>Schemacop::Exceptions</small></div></li></ul></li><li id='object_Schemacop::FieldNode' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/FieldNode.html" title="Schemacop::FieldNode (class)">FieldNode</a></span> < NodeSupportingType<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::FloatValidator' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/FloatValidator.html" title="Schemacop::FloatValidator (class)">FloatValidator</a></span> < NumberValidator<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::HashValidator' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/HashValidator.html" title="Schemacop::HashValidator (class)">HashValidator</a></span> < NodeSupportingField<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::IntegerValidator' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/IntegerValidator.html" title="Schemacop::IntegerValidator (class)">IntegerValidator</a></span> < NumberValidator<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::NilValidator' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/NilValidator.html" title="Schemacop::NilValidator (class)">NilValidator</a></span> < Node<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::Node' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/Node.html" title="Schemacop::Node (class)">Node</a></span> < Object<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::NodeResolver' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/NodeResolver.html" title="Schemacop::NodeResolver (class)">NodeResolver</a></span> < Object<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::NodeSupportingField' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/NodeSupportingField.html" title="Schemacop::NodeSupportingField (class)">NodeSupportingField</a></span> < NodeWithBlock<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::NodeSupportingType' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/NodeSupportingType.html" title="Schemacop::NodeSupportingType (class)">NodeSupportingType</a></span> < NodeWithBlock<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::NodeWithBlock' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/NodeWithBlock.html" title="Schemacop::NodeWithBlock (class)">NodeWithBlock</a></span> < Node<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::NumberValidator' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/NumberValidator.html" title="Schemacop::NumberValidator (class)">NumberValidator</a></span> < Node<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::ObjectValidator' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/ObjectValidator.html" title="Schemacop::ObjectValidator (class)">ObjectValidator</a></span> < Node<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::RootNode' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/RootNode.html" title="Schemacop::RootNode (class)">RootNode</a></span> < NodeSupportingType<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::Schema' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/Schema.html" title="Schemacop::Schema (class)">Schema</a></span> < Object<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::StringValidator' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/StringValidator.html" title="Schemacop::StringValidator (class)">StringValidator</a></span> < Node<small class='search_info'>Schemacop</small></div></li><li id='object_Schemacop::SymbolValidator' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Schemacop/SymbolValidator.html" title="Schemacop::SymbolValidator (class)">SymbolValidator</a></span> < Node<small class='search_info'>Schemacop</small></div></li></ul></li><li id='object_ScopedEnv' class='odd'><div class='item' style='padding-left:30px'><span class='object_link'><a href="ScopedEnv.html" title="ScopedEnv (class)">ScopedEnv</a></span> < Object<small class='search_info'>Top Level Namespace</small></div></li>
|
47
47
|
|
48
48
|
</ul>
|
49
49
|
</div>
|
data/doc/file.README.html
CHANGED
@@ -280,8 +280,8 @@ option <code>min</code> is supported by the <code>:string</code> validator (cove
|
|
280
280
|
|
281
281
|
<h3>Field Line</h3>
|
282
282
|
|
283
|
-
<p>Inside a Type Line of type <code>:hash</code
|
284
|
-
|
283
|
+
<p>Inside a Type Line of type <code>:hash</code>, you may specify an arbitrary number of field
|
284
|
+
lines (one for each key-value pair you want to be in the hash).</p>
|
285
285
|
|
286
286
|
<p>Field Lines start with one of the following six identifiers: <code>req</code>, <code>req?</code>,
|
287
287
|
<code>req!</code>, <code>opt</code>, <code>opt?</code> or <code>opt!</code>:</p>
|
@@ -327,12 +327,41 @@ non-nil field of type Integer or Date under the key <code>:age</code>.</p>
|
|
327
327
|
<p>You might find the notation cumbersome, and you'd be right to say so. Luckily
|
328
328
|
there are plenty of short forms available which we will see below.</p>
|
329
329
|
|
330
|
+
<h4>Handling hashes with indifferent access</h4>
|
331
|
+
|
332
|
+
<p>Schemacop has special handling for objects of the class
|
333
|
+
<code>ActiveSupport::HashWithIndifferentAccess</code>: You may specify the keys as symbols
|
334
|
+
or strings, and Schemacop will handle the conversion necessary for proper
|
335
|
+
validation internally. Note that if you define the same key as string and
|
336
|
+
symbol, it will throw a <code>ValidationError</code> <a href="#exceptions">exception</a> when asked to
|
337
|
+
validate a hash with indifferent access.</p>
|
338
|
+
|
339
|
+
<p>Thus, the following two schema definitions are equivalent when validating a hash
|
340
|
+
with indifferent access:</p>
|
341
|
+
|
342
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>Schema</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='kw'>do</span>
|
343
|
+
<span class='id identifier rubyid_type'>type</span> <span class='symbol'>:hash</span> <span class='kw'>do</span>
|
344
|
+
<span class='id identifier rubyid_req'>req</span> <span class='symbol'>:name</span> <span class='kw'>do</span>
|
345
|
+
<span class='id identifier rubyid_type'>type</span> <span class='symbol'>:string</span>
|
346
|
+
<span class='kw'>end</span>
|
347
|
+
<span class='kw'>end</span>
|
348
|
+
<span class='kw'>end</span>
|
349
|
+
|
350
|
+
<span class='const'>Schema</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='kw'>do</span>
|
351
|
+
<span class='id identifier rubyid_type'>type</span> <span class='symbol'>:hash</span> <span class='kw'>do</span>
|
352
|
+
<span class='id identifier rubyid_req'>req</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>name</span><span class='tstring_end'>'</span></span> <span class='kw'>do</span>
|
353
|
+
<span class='id identifier rubyid_type'>type</span> <span class='symbol'>:string</span>
|
354
|
+
<span class='kw'>end</span>
|
355
|
+
<span class='kw'>end</span>
|
356
|
+
<span class='kw'>end</span>
|
357
|
+
</code></pre>
|
358
|
+
|
330
359
|
<h2>Types</h2>
|
331
360
|
|
332
|
-
<p>
|
361
|
+
<p>Types are defined via their validators, which is a class under <code>validator/</code>.
|
362
|
+
Each validator is sourced by <code>schemacop.rb</code>.</p>
|
333
363
|
|
334
|
-
|
335
|
-
another `your_validator.rb` class under `validator/`): -->
|
364
|
+
<p>The following types are supported by Schemacop by default:</p>
|
336
365
|
|
337
366
|
<ul>
|
338
367
|
<li><p><code>:boolean</code> accepts a Ruby TrueClass or FalseClass instance.</p></li>
|
@@ -356,6 +385,7 @@ another `your_validator.rb` class under `validator/`): -->
|
|
356
385
|
<ul>
|
357
386
|
<li>supported options: <code>min</code>, <code>max</code> (bounds for string length)</li>
|
358
387
|
</ul></li>
|
388
|
+
<li><p><code>:symbol</code> accepts a Ruby Symbol.</p></li>
|
359
389
|
<li><p><code>:object</code> accepts an arbitrary Ruby object (any object if no option is given).</p>
|
360
390
|
|
361
391
|
<ul>
|
@@ -373,7 +403,7 @@ own validation (e.g. through the option <code>check</code>).</li>
|
|
373
403
|
<li>TODO no lookahead for different arrays, see
|
374
404
|
validator_array_test#test_multiple_arrays</li>
|
375
405
|
</ul></li>
|
376
|
-
<li><p><code>:hash</code> accepts a Ruby Hash
|
406
|
+
<li><p><code>:hash</code> accepts a Ruby Hash or an <code>ActiveSupport::HashWithIndifferentAccess</code>.</p>
|
377
407
|
|
378
408
|
<ul>
|
379
409
|
<li>accepts a block with an arbitrary number of Field Lines.</li>
|
@@ -589,7 +619,7 @@ to <a href="http://www.subgit.com/">SubGit</a> for their great open source licen
|
|
589
619
|
</div></div>
|
590
620
|
|
591
621
|
<div id="footer">
|
592
|
-
Generated on
|
622
|
+
Generated on Wed May 17 10:53:58 2017 by
|
593
623
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
594
624
|
0.9.9 (ruby-2.3.1).
|
595
625
|
</div>
|
data/doc/index.html
CHANGED
@@ -280,8 +280,8 @@ option <code>min</code> is supported by the <code>:string</code> validator (cove
|
|
280
280
|
|
281
281
|
<h3>Field Line</h3>
|
282
282
|
|
283
|
-
<p>Inside a Type Line of type <code>:hash</code
|
284
|
-
|
283
|
+
<p>Inside a Type Line of type <code>:hash</code>, you may specify an arbitrary number of field
|
284
|
+
lines (one for each key-value pair you want to be in the hash).</p>
|
285
285
|
|
286
286
|
<p>Field Lines start with one of the following six identifiers: <code>req</code>, <code>req?</code>,
|
287
287
|
<code>req!</code>, <code>opt</code>, <code>opt?</code> or <code>opt!</code>:</p>
|
@@ -327,12 +327,41 @@ non-nil field of type Integer or Date under the key <code>:age</code>.</p>
|
|
327
327
|
<p>You might find the notation cumbersome, and you'd be right to say so. Luckily
|
328
328
|
there are plenty of short forms available which we will see below.</p>
|
329
329
|
|
330
|
+
<h4>Handling hashes with indifferent access</h4>
|
331
|
+
|
332
|
+
<p>Schemacop has special handling for objects of the class
|
333
|
+
<code>ActiveSupport::HashWithIndifferentAccess</code>: You may specify the keys as symbols
|
334
|
+
or strings, and Schemacop will handle the conversion necessary for proper
|
335
|
+
validation internally. Note that if you define the same key as string and
|
336
|
+
symbol, it will throw a <code>ValidationError</code> <a href="#exceptions">exception</a> when asked to
|
337
|
+
validate a hash with indifferent access.</p>
|
338
|
+
|
339
|
+
<p>Thus, the following two schema definitions are equivalent when validating a hash
|
340
|
+
with indifferent access:</p>
|
341
|
+
|
342
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>Schema</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='kw'>do</span>
|
343
|
+
<span class='id identifier rubyid_type'>type</span> <span class='symbol'>:hash</span> <span class='kw'>do</span>
|
344
|
+
<span class='id identifier rubyid_req'>req</span> <span class='symbol'>:name</span> <span class='kw'>do</span>
|
345
|
+
<span class='id identifier rubyid_type'>type</span> <span class='symbol'>:string</span>
|
346
|
+
<span class='kw'>end</span>
|
347
|
+
<span class='kw'>end</span>
|
348
|
+
<span class='kw'>end</span>
|
349
|
+
|
350
|
+
<span class='const'>Schema</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='kw'>do</span>
|
351
|
+
<span class='id identifier rubyid_type'>type</span> <span class='symbol'>:hash</span> <span class='kw'>do</span>
|
352
|
+
<span class='id identifier rubyid_req'>req</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>name</span><span class='tstring_end'>'</span></span> <span class='kw'>do</span>
|
353
|
+
<span class='id identifier rubyid_type'>type</span> <span class='symbol'>:string</span>
|
354
|
+
<span class='kw'>end</span>
|
355
|
+
<span class='kw'>end</span>
|
356
|
+
<span class='kw'>end</span>
|
357
|
+
</code></pre>
|
358
|
+
|
330
359
|
<h2>Types</h2>
|
331
360
|
|
332
|
-
<p>
|
361
|
+
<p>Types are defined via their validators, which is a class under <code>validator/</code>.
|
362
|
+
Each validator is sourced by <code>schemacop.rb</code>.</p>
|
333
363
|
|
334
|
-
|
335
|
-
another `your_validator.rb` class under `validator/`): -->
|
364
|
+
<p>The following types are supported by Schemacop by default:</p>
|
336
365
|
|
337
366
|
<ul>
|
338
367
|
<li><p><code>:boolean</code> accepts a Ruby TrueClass or FalseClass instance.</p></li>
|
@@ -356,6 +385,7 @@ another `your_validator.rb` class under `validator/`): -->
|
|
356
385
|
<ul>
|
357
386
|
<li>supported options: <code>min</code>, <code>max</code> (bounds for string length)</li>
|
358
387
|
</ul></li>
|
388
|
+
<li><p><code>:symbol</code> accepts a Ruby Symbol.</p></li>
|
359
389
|
<li><p><code>:object</code> accepts an arbitrary Ruby object (any object if no option is given).</p>
|
360
390
|
|
361
391
|
<ul>
|
@@ -373,7 +403,7 @@ own validation (e.g. through the option <code>check</code>).</li>
|
|
373
403
|
<li>TODO no lookahead for different arrays, see
|
374
404
|
validator_array_test#test_multiple_arrays</li>
|
375
405
|
</ul></li>
|
376
|
-
<li><p><code>:hash</code> accepts a Ruby Hash
|
406
|
+
<li><p><code>:hash</code> accepts a Ruby Hash or an <code>ActiveSupport::HashWithIndifferentAccess</code>.</p>
|
377
407
|
|
378
408
|
<ul>
|
379
409
|
<li>accepts a block with an arbitrary number of Field Lines.</li>
|
@@ -589,7 +619,7 @@ to <a href="http://www.subgit.com/">SubGit</a> for their great open source licen
|
|
589
619
|
</div></div>
|
590
620
|
|
591
621
|
<div id="footer">
|
592
|
-
Generated on
|
622
|
+
Generated on Wed May 17 10:53:58 2017 by
|
593
623
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
594
624
|
0.9.9 (ruby-2.3.1).
|
595
625
|
</div>
|
@@ -102,7 +102,7 @@
|
|
102
102
|
</div>
|
103
103
|
|
104
104
|
<div id="footer">
|
105
|
-
Generated on
|
105
|
+
Generated on Wed May 17 10:53:58 2017 by
|
106
106
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
107
107
|
0.9.9 (ruby-2.3.1).
|
108
108
|
</div>
|
data/lib/schemacop.rb
CHANGED
@@ -3,6 +3,7 @@ end
|
|
3
3
|
|
4
4
|
require 'set'
|
5
5
|
require 'active_support/core_ext/class/attribute'
|
6
|
+
require 'active_support/hash_with_indifferent_access'
|
6
7
|
|
7
8
|
require 'schemacop/scoped_env'
|
8
9
|
require 'schemacop/exceptions'
|
@@ -21,6 +22,7 @@ require 'schemacop/validator/hash_validator'
|
|
21
22
|
require 'schemacop/validator/number_validator'
|
22
23
|
require 'schemacop/validator/integer_validator'
|
23
24
|
require 'schemacop/validator/float_validator'
|
25
|
+
require 'schemacop/validator/symbol_validator'
|
24
26
|
require 'schemacop/validator/string_validator'
|
25
27
|
require 'schemacop/validator/nil_validator'
|
26
28
|
require 'schemacop/validator/object_validator' # Matches any object, must be last validator
|
@@ -23,7 +23,7 @@ module Schemacop
|
|
23
23
|
field(*args, required: true, allow_nil: false, &block)
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
alias_method :req, :req!
|
27
27
|
|
28
28
|
def opt?(*args, &block)
|
29
29
|
field(*args, required: false, allow_nil: true, &block)
|
@@ -33,7 +33,7 @@ module Schemacop
|
|
33
33
|
field(*args, required: false, allow_nil: false, &block)
|
34
34
|
end
|
35
35
|
|
36
|
-
|
36
|
+
alias_method :opt, :opt?
|
37
37
|
|
38
38
|
protected
|
39
39
|
|
@@ -42,7 +42,6 @@ module Schemacop
|
|
42
42
|
# options = args.last.is_a?(Hash) ? args.pop : {}
|
43
43
|
name = args.shift
|
44
44
|
|
45
|
-
# rubocop: disable Style/IfInsideElse
|
46
45
|
if @fields[name]
|
47
46
|
@fields[name].type(*args, &block)
|
48
47
|
else
|
@@ -54,7 +53,6 @@ module Schemacop
|
|
54
53
|
@fields[name] = FieldNode.new(name, required, &block)
|
55
54
|
end
|
56
55
|
end
|
57
|
-
# rubocop: enable Style/IfInsideElse
|
58
56
|
|
59
57
|
@fields[name].type(:nil) if allow_nil
|
60
58
|
end
|
@@ -5,8 +5,21 @@ module Schemacop
|
|
5
5
|
def validate(data, collector)
|
6
6
|
super
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
if data.is_a? ActiveSupport::HashWithIndifferentAccess
|
9
|
+
allowed_fields = @fields.keys.map { |k| k.is_a?(String) ? k.to_sym : k }
|
10
|
+
data_keys = data.keys.map { |k| k.is_a?(String) ? k.to_sym : k }
|
11
|
+
|
12
|
+
# If the same key is specified in the schema as string and symbol, we
|
13
|
+
# definitely expect a Ruby hash and not one with indifferent access
|
14
|
+
if @fields.keys.length != Set.new(allowed_fields).length
|
15
|
+
fail Exceptions::ValidationError, 'Hash expected, but got ActiveSupport::HashWithIndifferentAccess.'
|
16
|
+
end
|
17
|
+
else
|
18
|
+
allowed_fields = @fields.keys
|
19
|
+
data_keys = data.keys
|
20
|
+
end
|
21
|
+
|
22
|
+
obsolete_keys = data_keys - allowed_fields
|
10
23
|
|
11
24
|
collector.error "Obsolete keys: #{obsolete_keys.inspect}." if obsolete_keys.any?
|
12
25
|
|