kharon 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzczMmFkMWJhZGQ5ODMwN2NjYTE2YTE0N2IxMGQzYWEzNmNiZjRmYg==
4
+ ZWM0YTEzZTQ2MTZjOGMxMTQzMTVkMDFhZWNjOTljMTFkY2QxNTQyMA==
5
5
  data.tar.gz: !binary |-
6
- OTc5ZTY2MDUyOTQ0MTU4MWY4NGMxMjRlOTE4NzkyNzE5MTMxYTE3Mw==
6
+ OWVmZTUzOTZmNGQxNmE0NmIxZGNhZTcyZDI5YzM1Njc4NDQ3YTYyZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzZhNDIxNjY3ODI4NWY5NzA4NTU2NzZkY2QzNzJkYjI3NjM1YTI0YThiNjEz
10
- NmFiNzM0NjQ1YzE1OTA5ZjQ1MjM1N2Y5YWFjODk4MTcwODMyMTIwMWRlZjlk
11
- MzE1ZWIzZjhkYWYzZWZjNWM1ODdjODc5MmJiZjM0MmQ0OWE0ZGY=
9
+ OWQwNjQ5ZDZmZWE4NzdkZDY5NDg1ZmY1Y2UwNGYyMjhjYzlmZjk2YjM1OWQx
10
+ ZmE1MjFhOTFhODg5NmE2YjE1MDkxZTQ2NjdhNDhiY2Y5M2E0ZGE2ZDQ1ZDRj
11
+ YzY1MjZhMWIxZDQyODIzODU5NDZhOWI4NGIzNWYyYjFlMGVjODQ=
12
12
  data.tar.gz: !binary |-
13
- MmNjNGU0OTlhMGI5MTBmYWI4Yzg2NGY2N2ZiZmVjMzJlNmJjODFjNjAyZDc2
14
- YzljNjc1N2QyM2U5NGRmNDY5MmRkZTIzMWUyMGY4ODMzOWJhZTQ1NmFjYzQz
15
- YWE1Mzc3OWU1N2NmMGNhZTMwMjExZmJlNDFjYzM3ZWUyZTlhYzg=
13
+ YTIxNDI4N2I3NTMyOTBlZTIxOTkyNDkzOTM3NTI0NDk2ZDU2OGUxMzhkNmIw
14
+ MGEwMGNkZDY3NzkzZGYwNGQ5YmM2OTY4NGIyYzA0ZDQxOGViODRkODkyN2Ey
15
+ MWRiMjAyNDE3YTI2MWQxYjYyOTVhM2U3MzBjYmI3MDJhY2Y4YTY=
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kharon (1.1.0)
4
+ kharon (1.0.0)
5
5
  bson (~> 2.2, >= 2.2.2)
6
6
 
7
7
  GEM
@@ -39,3 +39,6 @@ DEPENDENCIES
39
39
  redcarpet (= 3.3.1)
40
40
  rspec (~> 3.0, >= 3.0.0)
41
41
  yard (~> 0.8)
42
+
43
+ BUNDLED WITH
44
+ 1.12.3
data/README.md CHANGED
@@ -96,27 +96,30 @@ validator = Kharon::Validator.new(hash_to_validate)
96
96
  Now your validator knows which hash it has to validate, now you can do :
97
97
 
98
98
  ```ruby
99
- # Sees if the "required_integer_key" key is present, and an integer
100
- validator.integer("required_integer_key", required: true)
99
+ # Sees if the :required_integer_key key is present, and an integer
100
+ validator.integer(:required_integer_key, required: true)
101
101
  ```
102
102
 
103
+ Note: all keys are converted in symbols, and you must use symbols in all method calls on a validator.
104
+
103
105
  All the functions are listed in the full documentation below.
104
106
 
105
107
  ### The helper
106
108
 
107
- This gem was firstly designed to be used as a helper for Sinatra applications, so it contains another useful module : Kharon::Helpers. To use it in your Sinatra application, just type this in the controllers where you want it included :
108
-
109
- ```ruby
110
- helpers Kharon::Helpers
111
- ```
112
-
113
- From there, you can type it in any of the routes of this controller :
109
+ This gem was firstly designed to be used in controllers for Rails or Sinatra applications. To use it easily in such a context, include the Kharon::Validate module and the validate method, for example for a Rails controller :
114
110
 
115
111
  ```ruby
116
- validate(hash_to_validate) do
117
- integer "required_integer_key", required: true
112
+ class DummyController < ApplicationController
113
+ include Kharon::Validate
114
+
115
+ def show
116
+ validate(params) do
117
+ mongoid :id
118
+ end
119
+ end
118
120
  end
119
121
  ```
122
+ ```
120
123
 
121
124
  This code is strictly equivalent to the one presented above, it uses the block syntax of ruby to give you a nice and fancy way to validate your datas !
122
125
 
@@ -170,7 +173,11 @@ This option is used to give an array of possible values for the given key. If th
170
173
 
171
174
  #### :equals
172
175
 
173
- For the value of a given key in the hash to be equal to the given value. It can be used with all methods.
176
+ this method compares the value of the given key in the hash to be equal to the given value. It can be used with all methods.
177
+
178
+ #### :equals_key
179
+
180
+ this method compares the value of the given key in the hash to be equal to the value associated with the compared key in the same hash. It can be used with all methods.
174
181
 
175
182
  #### :min
176
183
 
@@ -229,7 +236,16 @@ The value of this option must be passed as a box. When given, this option indica
229
236
 
230
237
  In Kharon, errors are formatted in a particular way. Each error contains a hash (or associative array) describing its type, and giving special caracteristics if necessary.
231
238
 
232
- #### Type error
239
+ #### standard error
240
+
241
+ This error is the one raised when an error occurs that has nothing to deal with the validation itself. It's mainly raised when a ruby errors occurs. It's formatted as followed :
242
+
243
+ - type: always has the value "standard"
244
+ - exception: the type of the exception
245
+ - message: the formatted message for the exception
246
+ - backtrace: the whole backtrace for the exception
247
+
248
+ #### type error
233
249
 
234
250
  The most common error. It's raised when a type is expected for a key, and the given type for this key is different. It's formatted as followed :
235
251
 
Binary file
@@ -80,7 +80,7 @@
80
80
 
81
81
  <dt class="r1 last">Defined in:</dt>
82
82
  <dd class="r1 last">lib/kharon.rb<span class="defines">,<br />
83
- lib/kharon/errors.rb,<br /> lib/kharon/version.rb,<br /> lib/kharon/handlers.rb,<br /> lib/kharon/validator.rb,<br /> lib/kharon/errors/validation.rb,<br /> lib/kharon/handlers/messages.rb,<br /> lib/kharon/handlers/exceptions.rb</span>
83
+ lib/kharon/errors.rb,<br /> lib/kharon/version.rb,<br /> lib/kharon/validate.rb,<br /> lib/kharon/handlers.rb,<br /> lib/kharon/validator.rb,<br /> lib/kharon/errors/validation.rb,<br /> lib/kharon/handlers/messages.rb,<br /> lib/kharon/handlers/exceptions.rb</span>
84
84
  </dd>
85
85
 
86
86
  </dl>
@@ -117,7 +117,7 @@
117
117
  <p class="children">
118
118
 
119
119
 
120
- <strong class="modules">Modules:</strong> <span class='object_link'><a href="Kharon/Errors.html" title="Kharon::Errors (module)">Errors</a></span>, <span class='object_link'><a href="Kharon/Handlers.html" title="Kharon::Handlers (module)">Handlers</a></span>
120
+ <strong class="modules">Modules:</strong> <span class='object_link'><a href="Kharon/Errors.html" title="Kharon::Errors (module)">Errors</a></span>, <span class='object_link'><a href="Kharon/Handlers.html" title="Kharon::Handlers (module)">Handlers</a></span>, <span class='object_link'><a href="Kharon/Validate.html" title="Kharon::Validate (module)">Validate</a></span>
121
121
 
122
122
 
123
123
 
@@ -144,7 +144,7 @@
144
144
 
145
145
  </div>
146
146
  </dt>
147
- <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>1.1.0</span><span class='tstring_end'>&quot;</span></span></pre></dd>
147
+ <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>1.0.0</span><span class='tstring_end'>&quot;</span></span></pre></dd>
148
148
 
149
149
  <dt id="use_exceptions-classvariable" class="">@@use_exceptions =
150
150
 
@@ -355,7 +355,7 @@ stores error messages.</p>
355
355
  </div>
356
356
 
357
357
  <div id="footer">
358
- Generated on Tue Sep 15 10:54:07 2015 by
358
+ Generated on Tue May 17 11:54:24 2016 by
359
359
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
360
360
  0.8.7.6 (ruby-1.9.3).
361
361
  </div>
@@ -136,7 +136,7 @@ the application.</p>
136
136
  </div>
137
137
 
138
138
  <div id="footer">
139
- Generated on Tue Sep 15 10:54:07 2015 by
139
+ Generated on Tue May 17 11:54:24 2016 by
140
140
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
141
141
  0.8.7.6 (ruby-1.9.3).
142
142
  </div>
@@ -427,7 +427,7 @@ error in the validation.</p>
427
427
  </div>
428
428
 
429
429
  <div id="footer">
430
- Generated on Tue Sep 15 10:54:08 2015 by
430
+ Generated on Tue May 17 11:54:25 2016 by
431
431
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
432
432
  0.8.7.6 (ruby-1.9.3).
433
433
  </div>
@@ -135,7 +135,7 @@
135
135
  </div>
136
136
 
137
137
  <div id="footer">
138
- Generated on Tue Sep 15 10:54:07 2015 by
138
+ Generated on Tue May 17 11:54:24 2016 by
139
139
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
140
140
  0.8.7.6 (ruby-1.9.3).
141
141
  </div>
@@ -264,7 +264,7 @@ during validation.</p>
264
264
  </div>
265
265
 
266
266
  <div id="footer">
267
- Generated on Tue Sep 15 10:54:08 2015 by
267
+ Generated on Tue May 17 11:54:25 2016 by
268
268
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
269
269
  0.8.7.6 (ruby-1.9.3).
270
270
  </div>
@@ -416,7 +416,7 @@ the report_error method</p>
416
416
  </div>
417
417
 
418
418
  <div id="footer">
419
- Generated on Tue Sep 15 10:54:08 2015 by
419
+ Generated on Tue May 17 11:54:25 2016 by
420
420
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
421
421
  0.8.7.6 (ruby-1.9.3).
422
422
  </div>
@@ -0,0 +1,276 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>
7
+ Module: Kharon::Validate
8
+
9
+ &mdash; Documentation by YARD 0.8.7.6
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
+ hasFrames = window.top.frames.main ? true : false;
19
+ relpath = '../';
20
+ framesUrl = "../frames.html#!Kharon/Validate.html";
21
+ </script>
22
+
23
+
24
+ <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
25
+
26
+ <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
27
+
28
+
29
+ </head>
30
+ <body>
31
+ <div id="header">
32
+ <div id="menu">
33
+
34
+ <a href="../_index.html">Index (V)</a> &raquo;
35
+ <span class='title'><span class='object_link'><a href="../Kharon.html" title="Kharon (module)">Kharon</a></span></span>
36
+ &raquo;
37
+ <span class="title">Validate</span>
38
+
39
+
40
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
41
+ </div>
42
+
43
+ <div id="search">
44
+
45
+ <a class="full_list_link" id="class_list_link"
46
+ href="../class_list.html">
47
+ Class List
48
+ </a>
49
+
50
+ <a class="full_list_link" id="method_list_link"
51
+ href="../method_list.html">
52
+ Method List
53
+ </a>
54
+
55
+ <a class="full_list_link" id="file_list_link"
56
+ href="../file_list.html">
57
+ File List
58
+ </a>
59
+
60
+ </div>
61
+ <div class="clear"></div>
62
+ </div>
63
+
64
+ <iframe id="search_frame"></iframe>
65
+
66
+ <div id="content"><h1>Module: Kharon::Validate
67
+
68
+
69
+
70
+ </h1>
71
+
72
+ <dl class="box">
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+ <dt class="r1 last">Defined in:</dt>
82
+ <dd class="r1 last">lib/kharon/validate.rb</dd>
83
+
84
+ </dl>
85
+ <div class="clear"></div>
86
+
87
+ <h2>Overview</h2><div class="docstring">
88
+ <div class="discussion">
89
+
90
+ <p>Module to include to use the #validate method in your own classes. It
91
+ offers an easier way to validate datas than creating the validator from
92
+ scratch.</p>
93
+
94
+
95
+ </div>
96
+ </div>
97
+ <div class="tags">
98
+
99
+ <p class="tag_title">Author:</p>
100
+ <ul class="author">
101
+
102
+ <li>
103
+
104
+
105
+
106
+
107
+
108
+ <div class='inline'>
109
+ <p>Vincent Courtois &lt;courtois.vincent@outlook.com&gt;</p>
110
+ </div>
111
+
112
+ </li>
113
+
114
+ </ul>
115
+
116
+ </div>
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+ <h2>
125
+ Instance Method Summary
126
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
127
+ </h2>
128
+
129
+ <ul class="summary">
130
+
131
+ <li class="public ">
132
+ <span class="summary_signature">
133
+
134
+ <a href="#validate-instance_method" title="#validate (instance method)">- (Hash) <strong>validate</strong>(datas, &amp;block) </a>
135
+
136
+
137
+
138
+ </span>
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+ <span class="summary_desc"><div class='inline'>
149
+ <p>Validates the datas passed as parameter with a Kharon::Validator and the
150
+ given instructions.</p>
151
+ </div></span>
152
+
153
+ </li>
154
+
155
+
156
+ </ul>
157
+
158
+
159
+
160
+
161
+ <div id="instance_method_details" class="method_details_list">
162
+ <h2>Instance Method Details</h2>
163
+
164
+
165
+ <div class="method_details first">
166
+ <h3 class="signature first" id="validate-instance_method">
167
+
168
+ - (<tt>Hash</tt>) <strong>validate</strong>(datas, &amp;block)
169
+
170
+
171
+
172
+
173
+
174
+ </h3><div class="docstring">
175
+ <div class="discussion">
176
+
177
+ <p>Validates the datas passed as parameter with a Kharon::Validator and the
178
+ given instructions.</p>
179
+
180
+
181
+ </div>
182
+ </div>
183
+ <div class="tags">
184
+ <p class="tag_title">Parameters:</p>
185
+ <ul class="param">
186
+
187
+ <li>
188
+
189
+ <span class='name'>datas</span>
190
+
191
+
192
+ <span class='type'>(<tt>Hash</tt>)</span>
193
+
194
+
195
+
196
+ &mdash;
197
+ <div class='inline'>
198
+ <p>the parameters to validate with the given instructions.</p>
199
+ </div>
200
+
201
+ </li>
202
+
203
+ <li>
204
+
205
+ <span class='name'>block</span>
206
+
207
+
208
+ <span class='type'>(<tt>Proc</tt>)</span>
209
+
210
+
211
+
212
+ &mdash;
213
+ <div class='inline'>
214
+ <p>the instructions to apply on the validator.</p>
215
+ </div>
216
+
217
+ </li>
218
+
219
+ </ul>
220
+
221
+ <p class="tag_title">Returns:</p>
222
+ <ul class="return">
223
+
224
+ <li>
225
+
226
+
227
+ <span class='type'>(<tt>Hash</tt>)</span>
228
+
229
+
230
+
231
+ &mdash;
232
+ <div class='inline'>
233
+ <p>the validated and filtered datas.</p>
234
+ </div>
235
+
236
+ </li>
237
+
238
+ </ul>
239
+
240
+ </div><table class="source_code">
241
+ <tr>
242
+ <td>
243
+ <pre class="lines">
244
+
245
+
246
+ 9
247
+ 10
248
+ 11
249
+ 12
250
+ 13</pre>
251
+ </td>
252
+ <td>
253
+ <pre class="code"><span class="info file"># File 'lib/kharon/validate.rb', line 9</span>
254
+
255
+ <span class='kw'>def</span> <span class='id identifier rubyid_validate'>validate</span><span class='lparen'>(</span><span class='id identifier rubyid_datas'>datas</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
256
+ <span class='id identifier rubyid_validator'>validator</span> <span class='op'>=</span> <span class='const'>Kharon</span><span class='op'>::</span><span class='const'>Validator</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_datas'>datas</span><span class='rparen'>)</span>
257
+ <span class='id identifier rubyid_validator'>validator</span><span class='period'>.</span><span class='id identifier rubyid_instance_eval'>instance_eval</span><span class='lparen'>(</span><span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
258
+ <span class='kw'>return</span> <span class='id identifier rubyid_validator'>validator</span><span class='period'>.</span><span class='id identifier rubyid_filtered'>filtered</span>
259
+ <span class='kw'>end</span></pre>
260
+ </td>
261
+ </tr>
262
+ </table>
263
+ </div>
264
+
265
+ </div>
266
+
267
+ </div>
268
+
269
+ <div id="footer">
270
+ Generated on Tue May 17 11:54:24 2016 by
271
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
272
+ 0.8.7.6 (ruby-1.9.3).
273
+ </div>
274
+
275
+ </body>
276
+ </html>