sinatra-param 1.2.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +16 -0
- data/coverage/index.html +213 -153
- data/lib/sinatra/param.rb +22 -12
- data/lib/sinatra/param/version.rb +1 -1
- data/spec/dummy/app.rb +19 -2
- data/spec/{parameter_sets_spec.rb → parameter_exclusivity_spec.rb} +14 -5
- data/spec/parameter_raise_spec.rb +8 -1
- data/spec/parameter_spec.rb +5 -5
- data/spec/parameter_transformations_spec.rb +15 -8
- data/spec/parameter_type_coercion_spec.rb +44 -44
- data/spec/parameter_validations_spec.rb +39 -39
- metadata +4 -9
- data/sinatra-param-1.1.0.gem +0 -0
- data/sinatra-param-1.1.1.gem +0 -0
- data/sinatra-param-1.1.2.gem +0 -0
- data/sinatra-param-1.2.0.gem +0 -0
- data/sinatra-param-1.2.1.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41745f2481953252139149d9cd960c0d0ebfe218
|
4
|
+
data.tar.gz: 690bb03e1469f59231190f46b805a5bed38a0906
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 383b1b4052465f089c1c8c3d8cb5bd6527fb364e8acec1b7ddeeedd8ac021c598a755273fca0e25f260a757844942a4239b14980db89b6c7fb027b5aeec1b844
|
7
|
+
data.tar.gz: 31afa16492bd2030f635853bea4f698bfa8cc7e283c991a2f3fb5497a9bdb77ed0055e62c9aa04bbd81d0c0a967b894cb837f0fbde8a22af907aeb8c092e9917
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -35,6 +35,8 @@ class App < Sinatra::Base
|
|
35
35
|
param :order, String, in: ["ASC", "DESC"], transform: :upcase, default: "ASC"
|
36
36
|
param :price, String, format: "[<\=>]\s*\$\d+"
|
37
37
|
|
38
|
+
one_of :q, :categories
|
39
|
+
|
38
40
|
{...}.to_json
|
39
41
|
end
|
40
42
|
end
|
@@ -79,6 +81,18 @@ param :order, String, in: ["ASC", "DESC"], transform: :upcase, default: "ASC"
|
|
79
81
|
param :offset, Integer, min: 0, transform: lambda {|n| n - (n % 10)}
|
80
82
|
```
|
81
83
|
|
84
|
+
### Mutual Exclusivity
|
85
|
+
|
86
|
+
Using `one_of`, routes can specify two or more parameters to be mutually exclusive, and fail if more than one of those parameters is specified:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
param :a, String
|
90
|
+
param :b, String
|
91
|
+
param :c, String
|
92
|
+
|
93
|
+
one_of :a, :b, :c
|
94
|
+
```
|
95
|
+
|
82
96
|
### Exceptions
|
83
97
|
|
84
98
|
By default, when a parameter precondition fails, `Sinatra::Param` will `halt 400` with an error message:
|
@@ -106,6 +120,8 @@ Custom exception handling can also be enabled on an individual parameter basis,
|
|
106
120
|
|
107
121
|
```ruby
|
108
122
|
param :order, String, in: ["ASC", "DESC"], raise: true
|
123
|
+
|
124
|
+
one_of :q, :categories, raise: true
|
109
125
|
```
|
110
126
|
|
111
127
|
## Contact
|
data/coverage/index.html
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
<img src="./assets/0.7.1/loading.gif" alt="loading"/>
|
15
15
|
</div>
|
16
16
|
<div id="wrapper" style="display:none;">
|
17
|
-
<div class="timestamp">Generated <abbr class="timeago" title="
|
17
|
+
<div class="timestamp">Generated <abbr class="timeago" title="2015-01-20T09:50:50-08:00">2015-01-20T09:50:50-08:00</abbr></div>
|
18
18
|
<ul class="group_tabs"></ul>
|
19
19
|
|
20
20
|
<div id="content">
|
@@ -25,15 +25,15 @@
|
|
25
25
|
covered at
|
26
26
|
<span class="covered_strength">
|
27
27
|
<span class="green">
|
28
|
-
19.
|
28
|
+
19.8
|
29
29
|
</span>
|
30
30
|
</span> hits/line)
|
31
31
|
</h2>
|
32
32
|
<a name="AllFiles"></a>
|
33
33
|
<div>
|
34
34
|
<b>1</b> files in total.
|
35
|
-
<b>
|
36
|
-
<span class="green"><b>
|
35
|
+
<b>80</b> relevant lines.
|
36
|
+
<span class="green"><b>80</b> lines covered</span> and
|
37
37
|
<span class="red"><b>0</b> lines missed </span>
|
38
38
|
</div>
|
39
39
|
<table class="file_list">
|
@@ -53,11 +53,11 @@
|
|
53
53
|
<tr>
|
54
54
|
<td class="strong"><a href="#0f7926ededdfd8418773c107837b6dc4182659b8" class="src_link" title="lib/sinatra/param.rb">lib/sinatra/param.rb</a></td>
|
55
55
|
<td class="green strong">100.0 %</td>
|
56
|
-
<td>
|
57
|
-
<td>
|
58
|
-
<td>
|
56
|
+
<td>136</td>
|
57
|
+
<td>80</td>
|
58
|
+
<td>80</td>
|
59
59
|
<td>0</td>
|
60
|
-
<td>19.
|
60
|
+
<td>19.8</td>
|
61
61
|
</tr>
|
62
62
|
|
63
63
|
</tbody>
|
@@ -81,8 +81,8 @@
|
|
81
81
|
<h3>lib/sinatra/param.rb</h3>
|
82
82
|
<h4><span class="green">100.0 %</span> covered</h4>
|
83
83
|
<div>
|
84
|
-
<b>
|
85
|
-
<span class="green"><b>
|
84
|
+
<b>80</b> relevant lines.
|
85
|
+
<span class="green"><b>80</b> lines covered</span> and
|
86
86
|
<span class="red"><b>0</b> lines missed.</span>
|
87
87
|
</div>
|
88
88
|
</div>
|
@@ -174,8 +174,8 @@
|
|
174
174
|
<code class="ruby"> def param(name, type, options = {})</code>
|
175
175
|
</li>
|
176
176
|
|
177
|
-
<li class="covered" data-hits="
|
178
|
-
<span class="hits">
|
177
|
+
<li class="covered" data-hits="96" data-linenumber="15">
|
178
|
+
<span class="hits">96</span>
|
179
179
|
|
180
180
|
<code class="ruby"> name = name.to_s</code>
|
181
181
|
</li>
|
@@ -186,10 +186,10 @@
|
|
186
186
|
<code class="ruby"></code>
|
187
187
|
</li>
|
188
188
|
|
189
|
-
<li class="covered" data-hits="
|
190
|
-
<span class="hits">
|
189
|
+
<li class="covered" data-hits="96" data-linenumber="17">
|
190
|
+
<span class="hits">96</span>
|
191
191
|
|
192
|
-
<code class="ruby"> return unless params.member?(name) or
|
192
|
+
<code class="ruby"> return unless params.member?(name) or options[:default] or options[:required]</code>
|
193
193
|
</li>
|
194
194
|
|
195
195
|
<li class="never" data-hits="" data-linenumber="18">
|
@@ -198,44 +198,44 @@
|
|
198
198
|
<code class="ruby"></code>
|
199
199
|
</li>
|
200
200
|
|
201
|
-
<li class="covered" data-hits="
|
202
|
-
<span class="hits">
|
201
|
+
<li class="covered" data-hits="84" data-linenumber="19">
|
202
|
+
<span class="hits">84</span>
|
203
203
|
|
204
204
|
<code class="ruby"> begin</code>
|
205
205
|
</li>
|
206
206
|
|
207
|
-
<li class="covered" data-hits="
|
208
|
-
<span class="hits">
|
207
|
+
<li class="covered" data-hits="84" data-linenumber="20">
|
208
|
+
<span class="hits">84</span>
|
209
209
|
|
210
210
|
<code class="ruby"> params[name] = coerce(params[name], type, options)</code>
|
211
211
|
</li>
|
212
212
|
|
213
|
-
<li class="covered" data-hits="
|
214
|
-
<span class="hits">
|
213
|
+
<li class="covered" data-hits="79" data-linenumber="21">
|
214
|
+
<span class="hits">79</span>
|
215
215
|
|
216
216
|
<code class="ruby"> params[name] = (options[:default].call if options[:default].respond_to?(:call)) || options[:default] if params[name].nil? and options[:default]</code>
|
217
217
|
</li>
|
218
218
|
|
219
|
-
<li class="covered" data-hits="
|
220
|
-
<span class="hits">
|
219
|
+
<li class="covered" data-hits="79" data-linenumber="22">
|
220
|
+
<span class="hits">79</span>
|
221
221
|
|
222
|
-
<code class="ruby"> params[name] = options[:transform].to_proc.call(params[name]) if options[:transform]</code>
|
222
|
+
<code class="ruby"> params[name] = options[:transform].to_proc.call(params[name]) if params[name] and options[:transform]</code>
|
223
223
|
</li>
|
224
224
|
|
225
|
-
<li class="covered" data-hits="
|
226
|
-
<span class="hits">
|
225
|
+
<li class="covered" data-hits="79" data-linenumber="23">
|
226
|
+
<span class="hits">79</span>
|
227
227
|
|
228
228
|
<code class="ruby"> validate!(params[name], options)</code>
|
229
229
|
</li>
|
230
230
|
|
231
|
-
<li class="covered" data-hits="
|
232
|
-
<span class="hits">
|
231
|
+
<li class="covered" data-hits="22" data-linenumber="24">
|
232
|
+
<span class="hits">22</span>
|
233
233
|
|
234
234
|
<code class="ruby"> rescue InvalidParameterError => exception</code>
|
235
235
|
</li>
|
236
236
|
|
237
|
-
<li class="covered" data-hits="
|
238
|
-
<span class="hits">
|
237
|
+
<li class="covered" data-hits="22" data-linenumber="25">
|
238
|
+
<span class="hits">22</span>
|
239
239
|
|
240
240
|
<code class="ruby"> if options[:raise] or (settings.raise_sinatra_param_exceptions rescue false)</code>
|
241
241
|
</li>
|
@@ -264,20 +264,20 @@
|
|
264
264
|
<code class="ruby"></code>
|
265
265
|
</li>
|
266
266
|
|
267
|
-
<li class="covered" data-hits="
|
268
|
-
<span class="hits">
|
267
|
+
<li class="covered" data-hits="21" data-linenumber="30">
|
268
|
+
<span class="hits">21</span>
|
269
269
|
|
270
270
|
<code class="ruby"> error = "Invalid Parameter: #{name}"</code>
|
271
271
|
</li>
|
272
272
|
|
273
|
-
<li class="covered" data-hits="
|
274
|
-
<span class="hits">
|
273
|
+
<li class="covered" data-hits="21" data-linenumber="31">
|
274
|
+
<span class="hits">21</span>
|
275
275
|
|
276
276
|
<code class="ruby"> if content_type and content_type.match(mime_type(:json))</code>
|
277
277
|
</li>
|
278
278
|
|
279
|
-
<li class="covered" data-hits="
|
280
|
-
<span class="hits">
|
279
|
+
<li class="covered" data-hits="21" data-linenumber="32">
|
280
|
+
<span class="hits">21</span>
|
281
281
|
|
282
282
|
<code class="ruby"> error = {message: error, errors: {name => exception.message}}.to_json</code>
|
283
283
|
</li>
|
@@ -294,8 +294,8 @@
|
|
294
294
|
<code class="ruby"></code>
|
295
295
|
</li>
|
296
296
|
|
297
|
-
<li class="covered" data-hits="
|
298
|
-
<span class="hits">
|
297
|
+
<li class="covered" data-hits="21" data-linenumber="35">
|
298
|
+
<span class="hits">21</span>
|
299
299
|
|
300
300
|
<code class="ruby"> halt 400, error</code>
|
301
301
|
</li>
|
@@ -321,526 +321,586 @@
|
|
321
321
|
<li class="covered" data-hits="1" data-linenumber="39">
|
322
322
|
<span class="hits">1</span>
|
323
323
|
|
324
|
-
<code class="ruby"> def one_of(*
|
324
|
+
<code class="ruby"> def one_of(*args)</code>
|
325
325
|
</li>
|
326
326
|
|
327
|
-
<li class="covered" data-hits="
|
328
|
-
<span class="hits">
|
327
|
+
<li class="covered" data-hits="8" data-linenumber="40">
|
328
|
+
<span class="hits">8</span>
|
329
329
|
|
330
|
-
<code class="ruby">
|
330
|
+
<code class="ruby"> options = args.last.is_a?(Hash) ? args.pop : {}</code>
|
331
331
|
</li>
|
332
332
|
|
333
|
-
<li class="covered" data-hits="
|
334
|
-
<span class="hits">
|
333
|
+
<li class="covered" data-hits="8" data-linenumber="41">
|
334
|
+
<span class="hits">8</span>
|
335
335
|
|
336
|
-
<code class="ruby"> names
|
336
|
+
<code class="ruby"> names = args.collect(&:to_s)</code>
|
337
337
|
</li>
|
338
338
|
|
339
|
-
<li class="
|
340
|
-
|
339
|
+
<li class="never" data-hits="" data-linenumber="42">
|
340
|
+
|
341
341
|
|
342
|
-
<code class="ruby"
|
342
|
+
<code class="ruby"></code>
|
343
343
|
</li>
|
344
344
|
|
345
|
-
<li class="covered" data-hits="
|
346
|
-
<span class="hits">
|
345
|
+
<li class="covered" data-hits="8" data-linenumber="43">
|
346
|
+
<span class="hits">8</span>
|
347
347
|
|
348
|
-
<code class="ruby">
|
348
|
+
<code class="ruby"> return unless names.length > 2</code>
|
349
349
|
</li>
|
350
350
|
|
351
|
-
<li class="
|
352
|
-
<span class="hits">9</span>
|
351
|
+
<li class="never" data-hits="" data-linenumber="44">
|
353
352
|
|
354
|
-
|
353
|
+
|
354
|
+
<code class="ruby"></code>
|
355
355
|
</li>
|
356
356
|
|
357
|
-
<li class="
|
357
|
+
<li class="covered" data-hits="8" data-linenumber="45">
|
358
|
+
<span class="hits">8</span>
|
358
359
|
|
360
|
+
<code class="ruby"> begin</code>
|
361
|
+
</li>
|
362
|
+
|
363
|
+
<li class="covered" data-hits="8" data-linenumber="46">
|
364
|
+
<span class="hits">8</span>
|
359
365
|
|
360
|
-
<code class="ruby"
|
366
|
+
<code class="ruby"> validate_one_of!(params, names, options)</code>
|
361
367
|
</li>
|
362
368
|
|
363
|
-
<li class="covered" data-hits="
|
364
|
-
<span class="hits">
|
369
|
+
<li class="covered" data-hits="4" data-linenumber="47">
|
370
|
+
<span class="hits">4</span>
|
365
371
|
|
366
|
-
<code class="ruby">
|
372
|
+
<code class="ruby"> rescue InvalidParameterError => exception</code>
|
367
373
|
</li>
|
368
374
|
|
369
|
-
<li class="covered" data-hits="
|
370
|
-
<span class="hits">
|
375
|
+
<li class="covered" data-hits="4" data-linenumber="48">
|
376
|
+
<span class="hits">4</span>
|
371
377
|
|
372
|
-
<code class="ruby">
|
378
|
+
<code class="ruby"> if options[:raise] or (settings.raise_sinatra_param_exceptions rescue false)</code>
|
373
379
|
</li>
|
374
380
|
|
375
|
-
<li class="covered" data-hits="
|
376
|
-
<span class="hits">
|
381
|
+
<li class="covered" data-hits="1" data-linenumber="49">
|
382
|
+
<span class="hits">1</span>
|
377
383
|
|
378
|
-
<code class="ruby">
|
384
|
+
<code class="ruby"> exception.param, exception.options = names, options</code>
|
379
385
|
</li>
|
380
386
|
|
381
|
-
<li class="
|
387
|
+
<li class="covered" data-hits="1" data-linenumber="50">
|
388
|
+
<span class="hits">1</span>
|
389
|
+
|
390
|
+
<code class="ruby"> raise exception</code>
|
391
|
+
</li>
|
392
|
+
|
393
|
+
<li class="never" data-hits="" data-linenumber="51">
|
382
394
|
|
383
395
|
|
384
|
-
<code class="ruby">
|
396
|
+
<code class="ruby"> end</code>
|
385
397
|
</li>
|
386
398
|
|
387
|
-
<li class="never" data-hits="" data-linenumber="
|
399
|
+
<li class="never" data-hits="" data-linenumber="52">
|
388
400
|
|
389
401
|
|
390
402
|
<code class="ruby"></code>
|
391
403
|
</li>
|
392
404
|
|
393
|
-
<li class="covered" data-hits="3" data-linenumber="
|
405
|
+
<li class="covered" data-hits="3" data-linenumber="53">
|
394
406
|
<span class="hits">3</span>
|
395
407
|
|
396
|
-
<code class="ruby">
|
408
|
+
<code class="ruby"> error = "Parameters #{names.join(', ')} are mutually exclusive"</code>
|
397
409
|
</li>
|
398
410
|
|
399
|
-
<li class="
|
411
|
+
<li class="covered" data-hits="3" data-linenumber="54">
|
412
|
+
<span class="hits">3</span>
|
413
|
+
|
414
|
+
<code class="ruby"> if content_type and content_type.match(mime_type(:json))</code>
|
415
|
+
</li>
|
416
|
+
|
417
|
+
<li class="covered" data-hits="3" data-linenumber="55">
|
418
|
+
<span class="hits">3</span>
|
419
|
+
|
420
|
+
<code class="ruby"> error = {message: error, errors: {names => exception.message}}.to_json</code>
|
421
|
+
</li>
|
422
|
+
|
423
|
+
<li class="never" data-hits="" data-linenumber="56">
|
400
424
|
|
401
425
|
|
402
426
|
<code class="ruby"> end</code>
|
403
427
|
</li>
|
404
428
|
|
405
|
-
<li class="never" data-hits="" data-linenumber="
|
429
|
+
<li class="never" data-hits="" data-linenumber="57">
|
430
|
+
|
431
|
+
|
432
|
+
<code class="ruby"></code>
|
433
|
+
</li>
|
434
|
+
|
435
|
+
<li class="covered" data-hits="3" data-linenumber="58">
|
436
|
+
<span class="hits">3</span>
|
437
|
+
|
438
|
+
<code class="ruby"> halt 400, error</code>
|
439
|
+
</li>
|
440
|
+
|
441
|
+
<li class="never" data-hits="" data-linenumber="59">
|
406
442
|
|
407
443
|
|
408
444
|
<code class="ruby"> end</code>
|
409
445
|
</li>
|
410
446
|
|
411
|
-
<li class="never" data-hits="" data-linenumber="
|
447
|
+
<li class="never" data-hits="" data-linenumber="60">
|
412
448
|
|
413
449
|
|
414
450
|
<code class="ruby"> end</code>
|
415
451
|
</li>
|
416
452
|
|
417
|
-
<li class="never" data-hits="" data-linenumber="
|
453
|
+
<li class="never" data-hits="" data-linenumber="61">
|
418
454
|
|
419
455
|
|
420
456
|
<code class="ruby"></code>
|
421
457
|
</li>
|
422
458
|
|
423
|
-
<li class="covered" data-hits="1" data-linenumber="
|
459
|
+
<li class="covered" data-hits="1" data-linenumber="62">
|
424
460
|
<span class="hits">1</span>
|
425
461
|
|
426
462
|
<code class="ruby"> private</code>
|
427
463
|
</li>
|
428
464
|
|
429
|
-
<li class="never" data-hits="" data-linenumber="
|
465
|
+
<li class="never" data-hits="" data-linenumber="63">
|
430
466
|
|
431
467
|
|
432
468
|
<code class="ruby"></code>
|
433
469
|
</li>
|
434
470
|
|
435
|
-
<li class="covered" data-hits="1" data-linenumber="
|
471
|
+
<li class="covered" data-hits="1" data-linenumber="64">
|
436
472
|
<span class="hits">1</span>
|
437
473
|
|
438
474
|
<code class="ruby"> def coerce(param, type, options = {})</code>
|
439
475
|
</li>
|
440
476
|
|
441
|
-
<li class="covered" data-hits="
|
442
|
-
<span class="hits">
|
477
|
+
<li class="covered" data-hits="84" data-linenumber="65">
|
478
|
+
<span class="hits">84</span>
|
443
479
|
|
444
480
|
<code class="ruby"> begin</code>
|
445
481
|
</li>
|
446
482
|
|
447
|
-
<li class="covered" data-hits="
|
448
|
-
<span class="hits">
|
483
|
+
<li class="covered" data-hits="84" data-linenumber="66">
|
484
|
+
<span class="hits">84</span>
|
449
485
|
|
450
486
|
<code class="ruby"> return nil if param.nil?</code>
|
451
487
|
</li>
|
452
488
|
|
453
|
-
<li class="covered" data-hits="
|
454
|
-
<span class="hits">
|
489
|
+
<li class="covered" data-hits="77" data-linenumber="67">
|
490
|
+
<span class="hits">77</span>
|
455
491
|
|
456
492
|
<code class="ruby"> return param if (param.is_a?(type) rescue false)</code>
|
457
493
|
</li>
|
458
494
|
|
459
|
-
<li class="covered" data-hits="46" data-linenumber="
|
495
|
+
<li class="covered" data-hits="46" data-linenumber="68">
|
460
496
|
<span class="hits">46</span>
|
461
497
|
|
462
498
|
<code class="ruby"> return Integer(param) if type == Integer</code>
|
463
499
|
</li>
|
464
500
|
|
465
|
-
<li class="covered" data-hits="35" data-linenumber="
|
501
|
+
<li class="covered" data-hits="35" data-linenumber="69">
|
466
502
|
<span class="hits">35</span>
|
467
503
|
|
468
504
|
<code class="ruby"> return Float(param) if type == Float</code>
|
469
505
|
</li>
|
470
506
|
|
471
|
-
<li class="covered" data-hits="33" data-linenumber="
|
507
|
+
<li class="covered" data-hits="33" data-linenumber="70">
|
472
508
|
<span class="hits">33</span>
|
473
509
|
|
474
510
|
<code class="ruby"> return String(param) if type == String</code>
|
475
511
|
</li>
|
476
512
|
|
477
|
-
<li class="covered" data-hits="32" data-linenumber="
|
513
|
+
<li class="covered" data-hits="32" data-linenumber="71">
|
478
514
|
<span class="hits">32</span>
|
479
515
|
|
480
516
|
<code class="ruby"> return Date.parse(param) if type == Date</code>
|
481
517
|
</li>
|
482
518
|
|
483
|
-
<li class="covered" data-hits="30" data-linenumber="
|
519
|
+
<li class="covered" data-hits="30" data-linenumber="72">
|
484
520
|
<span class="hits">30</span>
|
485
521
|
|
486
522
|
<code class="ruby"> return Time.parse(param) if type == Time</code>
|
487
523
|
</li>
|
488
524
|
|
489
|
-
<li class="covered" data-hits="28" data-linenumber="
|
525
|
+
<li class="covered" data-hits="28" data-linenumber="73">
|
490
526
|
<span class="hits">28</span>
|
491
527
|
|
492
528
|
<code class="ruby"> return DateTime.parse(param) if type == DateTime</code>
|
493
529
|
</li>
|
494
530
|
|
495
|
-
<li class="covered" data-hits="26" data-linenumber="
|
531
|
+
<li class="covered" data-hits="26" data-linenumber="74">
|
496
532
|
<span class="hits">26</span>
|
497
533
|
|
498
534
|
<code class="ruby"> return Array(param.split(options[:delimiter] || ",")) if type == Array</code>
|
499
535
|
</li>
|
500
536
|
|
501
|
-
<li class="covered" data-hits="25" data-linenumber="
|
537
|
+
<li class="covered" data-hits="25" data-linenumber="75">
|
502
538
|
<span class="hits">25</span>
|
503
539
|
|
504
540
|
<code class="ruby"> return Hash[param.split(options[:delimiter] || ",").map{|c| c.split(options[:separator] || ":")}] if type == Hash</code>
|
505
541
|
</li>
|
506
542
|
|
507
|
-
<li class="covered" data-hits="21" data-linenumber="
|
543
|
+
<li class="covered" data-hits="21" data-linenumber="76">
|
508
544
|
<span class="hits">21</span>
|
509
545
|
|
510
546
|
<code class="ruby"> return (/(false|f|no|n|0)$/i === param.to_s ? false : (/(true|t|yes|y|1)$/i === param.to_s ? true : nil)) if type == TrueClass || type == FalseClass || type == Boolean</code>
|
511
547
|
</li>
|
512
548
|
|
513
|
-
<li class="never" data-hits="" data-linenumber="
|
549
|
+
<li class="never" data-hits="" data-linenumber="77">
|
514
550
|
|
515
551
|
|
516
552
|
<code class="ruby"> return nil</code>
|
517
553
|
</li>
|
518
554
|
|
519
|
-
<li class="covered" data-hits="5" data-linenumber="
|
555
|
+
<li class="covered" data-hits="5" data-linenumber="78">
|
520
556
|
<span class="hits">5</span>
|
521
557
|
|
522
558
|
<code class="ruby"> rescue ArgumentError</code>
|
523
559
|
</li>
|
524
560
|
|
525
|
-
<li class="covered" data-hits="5" data-linenumber="
|
561
|
+
<li class="covered" data-hits="5" data-linenumber="79">
|
526
562
|
<span class="hits">5</span>
|
527
563
|
|
528
564
|
<code class="ruby"> raise InvalidParameterError, "'#{param}' is not a valid #{type}"</code>
|
529
565
|
</li>
|
530
566
|
|
531
|
-
<li class="never" data-hits="" data-linenumber="
|
567
|
+
<li class="never" data-hits="" data-linenumber="80">
|
532
568
|
|
533
569
|
|
534
570
|
<code class="ruby"> end</code>
|
535
571
|
</li>
|
536
572
|
|
537
|
-
<li class="never" data-hits="" data-linenumber="
|
573
|
+
<li class="never" data-hits="" data-linenumber="81">
|
538
574
|
|
539
575
|
|
540
576
|
<code class="ruby"> end</code>
|
541
577
|
</li>
|
542
578
|
|
543
|
-
<li class="never" data-hits="" data-linenumber="
|
579
|
+
<li class="never" data-hits="" data-linenumber="82">
|
544
580
|
|
545
581
|
|
546
582
|
<code class="ruby"></code>
|
547
583
|
</li>
|
548
584
|
|
549
|
-
<li class="covered" data-hits="1" data-linenumber="
|
585
|
+
<li class="covered" data-hits="1" data-linenumber="83">
|
550
586
|
<span class="hits">1</span>
|
551
587
|
|
552
588
|
<code class="ruby"> def validate!(param, options)</code>
|
553
589
|
</li>
|
554
590
|
|
555
|
-
<li class="covered" data-hits="
|
556
|
-
<span class="hits">
|
591
|
+
<li class="covered" data-hits="79" data-linenumber="84">
|
592
|
+
<span class="hits">79</span>
|
557
593
|
|
558
594
|
<code class="ruby"> options.each do |key, value|</code>
|
559
595
|
</li>
|
560
596
|
|
561
|
-
<li class="covered" data-hits="
|
562
|
-
<span class="hits">
|
597
|
+
<li class="covered" data-hits="45" data-linenumber="85">
|
598
|
+
<span class="hits">45</span>
|
563
599
|
|
564
600
|
<code class="ruby"> case key</code>
|
565
601
|
</li>
|
566
602
|
|
567
|
-
<li class="never" data-hits="" data-linenumber="
|
603
|
+
<li class="never" data-hits="" data-linenumber="86">
|
568
604
|
|
569
605
|
|
570
606
|
<code class="ruby"> when :required</code>
|
571
607
|
</li>
|
572
608
|
|
573
|
-
<li class="covered" data-hits="
|
574
|
-
<span class="hits">
|
609
|
+
<li class="covered" data-hits="5" data-linenumber="87">
|
610
|
+
<span class="hits">5</span>
|
575
611
|
|
576
612
|
<code class="ruby"> raise InvalidParameterError, "Parameter is required" if value && param.nil?</code>
|
577
613
|
</li>
|
578
614
|
|
579
|
-
<li class="never" data-hits="" data-linenumber="
|
615
|
+
<li class="never" data-hits="" data-linenumber="88">
|
580
616
|
|
581
617
|
|
582
618
|
<code class="ruby"> when :blank</code>
|
583
619
|
</li>
|
584
620
|
|
585
|
-
<li class="never" data-hits="" data-linenumber="
|
621
|
+
<li class="never" data-hits="" data-linenumber="89">
|
586
622
|
|
587
623
|
|
588
624
|
<code class="ruby"> raise InvalidParameterError, "Parameter cannot be blank" if !value && case param</code>
|
589
625
|
</li>
|
590
626
|
|
591
|
-
<li class="never" data-hits="" data-linenumber="
|
627
|
+
<li class="never" data-hits="" data-linenumber="90">
|
592
628
|
|
593
629
|
|
594
630
|
<code class="ruby"> when String</code>
|
595
631
|
</li>
|
596
632
|
|
597
|
-
<li class="covered" data-hits="1" data-linenumber="
|
633
|
+
<li class="covered" data-hits="1" data-linenumber="91">
|
598
634
|
<span class="hits">1</span>
|
599
635
|
|
600
636
|
<code class="ruby"> !(/\S/ === param)</code>
|
601
637
|
</li>
|
602
638
|
|
603
|
-
<li class="never" data-hits="" data-linenumber="
|
639
|
+
<li class="never" data-hits="" data-linenumber="92">
|
604
640
|
|
605
641
|
|
606
642
|
<code class="ruby"> when Array, Hash</code>
|
607
643
|
</li>
|
608
644
|
|
609
|
-
<li class="covered" data-hits="2" data-linenumber="
|
645
|
+
<li class="covered" data-hits="2" data-linenumber="93">
|
610
646
|
<span class="hits">2</span>
|
611
647
|
|
612
648
|
<code class="ruby"> param.empty?</code>
|
613
649
|
</li>
|
614
650
|
|
615
|
-
<li class="never" data-hits="" data-linenumber="
|
651
|
+
<li class="never" data-hits="" data-linenumber="94">
|
616
652
|
|
617
653
|
|
618
654
|
<code class="ruby"> else</code>
|
619
655
|
</li>
|
620
656
|
|
621
|
-
<li class="covered" data-hits="1" data-linenumber="
|
657
|
+
<li class="covered" data-hits="1" data-linenumber="95">
|
622
658
|
<span class="hits">1</span>
|
623
659
|
|
624
660
|
<code class="ruby"> param.nil?</code>
|
625
661
|
</li>
|
626
662
|
|
627
|
-
<li class="covered" data-hits="5" data-linenumber="
|
663
|
+
<li class="covered" data-hits="5" data-linenumber="96">
|
628
664
|
<span class="hits">5</span>
|
629
665
|
|
630
666
|
<code class="ruby"> end</code>
|
631
667
|
</li>
|
632
668
|
|
633
|
-
<li class="never" data-hits="" data-linenumber="
|
669
|
+
<li class="never" data-hits="" data-linenumber="97">
|
634
670
|
|
635
671
|
|
636
672
|
<code class="ruby"> when :format</code>
|
637
673
|
</li>
|
638
674
|
|
639
|
-
<li class="covered" data-hits="3" data-linenumber="
|
675
|
+
<li class="covered" data-hits="3" data-linenumber="98">
|
640
676
|
<span class="hits">3</span>
|
641
677
|
|
642
678
|
<code class="ruby"> raise InvalidParameterError, "Parameter must be a string if using the format validation" unless param.kind_of?(String)</code>
|
643
679
|
</li>
|
644
680
|
|
645
|
-
<li class="covered" data-hits="2" data-linenumber="
|
681
|
+
<li class="covered" data-hits="2" data-linenumber="99">
|
646
682
|
<span class="hits">2</span>
|
647
683
|
|
648
684
|
<code class="ruby"> raise InvalidParameterError, "Parameter must match format #{value}" unless param =~ value</code>
|
649
685
|
</li>
|
650
686
|
|
651
|
-
<li class="never" data-hits="" data-linenumber="
|
687
|
+
<li class="never" data-hits="" data-linenumber="100">
|
652
688
|
|
653
689
|
|
654
690
|
<code class="ruby"> when :is</code>
|
655
691
|
</li>
|
656
692
|
|
657
|
-
<li class="covered" data-hits="2" data-linenumber="
|
693
|
+
<li class="covered" data-hits="2" data-linenumber="101">
|
658
694
|
<span class="hits">2</span>
|
659
695
|
|
660
696
|
<code class="ruby"> raise InvalidParameterError, "Parameter must be #{value}" unless param === value</code>
|
661
697
|
</li>
|
662
698
|
|
663
|
-
<li class="never" data-hits="" data-linenumber="
|
699
|
+
<li class="never" data-hits="" data-linenumber="102">
|
664
700
|
|
665
701
|
|
666
702
|
<code class="ruby"> when :in, :within, :range</code>
|
667
703
|
</li>
|
668
704
|
|
669
|
-
<li class="never" data-hits="" data-linenumber="
|
705
|
+
<li class="never" data-hits="" data-linenumber="103">
|
670
706
|
|
671
707
|
|
672
708
|
<code class="ruby"> raise InvalidParameterError, "Parameter must be within #{value}" unless param.nil? || case value</code>
|
673
709
|
</li>
|
674
710
|
|
675
|
-
<li class="never" data-hits="" data-linenumber="
|
711
|
+
<li class="never" data-hits="" data-linenumber="104">
|
676
712
|
|
677
713
|
|
678
714
|
<code class="ruby"> when Range</code>
|
679
715
|
</li>
|
680
716
|
|
681
|
-
<li class="covered" data-hits="4" data-linenumber="
|
717
|
+
<li class="covered" data-hits="4" data-linenumber="105">
|
682
718
|
<span class="hits">4</span>
|
683
719
|
|
684
720
|
<code class="ruby"> value.include?(param)</code>
|
685
721
|
</li>
|
686
722
|
|
687
|
-
<li class="never" data-hits="" data-linenumber="
|
723
|
+
<li class="never" data-hits="" data-linenumber="106">
|
688
724
|
|
689
725
|
|
690
726
|
<code class="ruby"> else</code>
|
691
727
|
</li>
|
692
728
|
|
693
|
-
<li class="covered" data-hits="2" data-linenumber="
|
729
|
+
<li class="covered" data-hits="2" data-linenumber="107">
|
694
730
|
<span class="hits">2</span>
|
695
731
|
|
696
732
|
<code class="ruby"> Array(value).include?(param)</code>
|
697
733
|
</li>
|
698
734
|
|
699
|
-
<li class="covered" data-hits="6" data-linenumber="
|
735
|
+
<li class="covered" data-hits="6" data-linenumber="108">
|
700
736
|
<span class="hits">6</span>
|
701
737
|
|
702
738
|
<code class="ruby"> end</code>
|
703
739
|
</li>
|
704
740
|
|
705
|
-
<li class="never" data-hits="" data-linenumber="
|
741
|
+
<li class="never" data-hits="" data-linenumber="109">
|
706
742
|
|
707
743
|
|
708
744
|
<code class="ruby"> when :min</code>
|
709
745
|
</li>
|
710
746
|
|
711
|
-
<li class="covered" data-hits="2" data-linenumber="
|
747
|
+
<li class="covered" data-hits="2" data-linenumber="110">
|
712
748
|
<span class="hits">2</span>
|
713
749
|
|
714
750
|
<code class="ruby"> raise InvalidParameterError, "Parameter cannot be less than #{value}" unless param.nil? || value <= param</code>
|
715
751
|
</li>
|
716
752
|
|
717
|
-
<li class="never" data-hits="" data-linenumber="
|
753
|
+
<li class="never" data-hits="" data-linenumber="111">
|
718
754
|
|
719
755
|
|
720
756
|
<code class="ruby"> when :max</code>
|
721
757
|
</li>
|
722
758
|
|
723
|
-
<li class="covered" data-hits="2" data-linenumber="
|
759
|
+
<li class="covered" data-hits="2" data-linenumber="112">
|
724
760
|
<span class="hits">2</span>
|
725
761
|
|
726
762
|
<code class="ruby"> raise InvalidParameterError, "Parameter cannot be greater than #{value}" unless param.nil? || value >= param</code>
|
727
763
|
</li>
|
728
764
|
|
729
|
-
<li class="never" data-hits="" data-linenumber="
|
765
|
+
<li class="never" data-hits="" data-linenumber="113">
|
730
766
|
|
731
767
|
|
732
768
|
<code class="ruby"> when :min_length</code>
|
733
769
|
</li>
|
734
770
|
|
735
|
-
<li class="covered" data-hits="1" data-linenumber="
|
771
|
+
<li class="covered" data-hits="1" data-linenumber="114">
|
736
772
|
<span class="hits">1</span>
|
737
773
|
|
738
774
|
<code class="ruby"> raise InvalidParameterError, "Parameter cannot have length less than #{value}" unless param.nil? || value <= param.length</code>
|
739
775
|
</li>
|
740
776
|
|
741
|
-
<li class="never" data-hits="" data-linenumber="
|
777
|
+
<li class="never" data-hits="" data-linenumber="115">
|
742
778
|
|
743
779
|
|
744
780
|
<code class="ruby"> when :max_length</code>
|
745
781
|
</li>
|
746
782
|
|
747
|
-
<li class="covered" data-hits="3" data-linenumber="
|
783
|
+
<li class="covered" data-hits="3" data-linenumber="116">
|
748
784
|
<span class="hits">3</span>
|
749
785
|
|
750
786
|
<code class="ruby"> raise InvalidParameterError, "Parameter cannot have length greater than #{value}" unless param.nil? || value >= param.length</code>
|
751
787
|
</li>
|
752
788
|
|
753
|
-
<li class="never" data-hits="" data-linenumber="
|
789
|
+
<li class="never" data-hits="" data-linenumber="117">
|
754
790
|
|
755
791
|
|
756
792
|
<code class="ruby"> end</code>
|
757
793
|
</li>
|
758
794
|
|
759
|
-
<li class="never" data-hits="" data-linenumber="
|
795
|
+
<li class="never" data-hits="" data-linenumber="118">
|
760
796
|
|
761
797
|
|
762
798
|
<code class="ruby"> end</code>
|
763
799
|
</li>
|
764
800
|
|
765
|
-
<li class="never" data-hits="" data-linenumber="
|
801
|
+
<li class="never" data-hits="" data-linenumber="119">
|
766
802
|
|
767
803
|
|
768
804
|
<code class="ruby"> end</code>
|
769
805
|
</li>
|
770
806
|
|
771
|
-
<li class="never" data-hits="" data-linenumber="
|
807
|
+
<li class="never" data-hits="" data-linenumber="120">
|
772
808
|
|
773
809
|
|
774
810
|
<code class="ruby"></code>
|
775
811
|
</li>
|
776
812
|
|
777
|
-
<li class="
|
813
|
+
<li class="covered" data-hits="1" data-linenumber="121">
|
814
|
+
<span class="hits">1</span>
|
815
|
+
|
816
|
+
<code class="ruby"> def validate_one_of!(params, names, options)</code>
|
817
|
+
</li>
|
818
|
+
|
819
|
+
<li class="covered" data-hits="32" data-linenumber="122">
|
820
|
+
<span class="hits">32</span>
|
821
|
+
|
822
|
+
<code class="ruby"> raise InvalidParameterError, "Parameters #{names.join(', ')} are mutually exclusive" if names.count{|name| present?(params[name])} > 1</code>
|
823
|
+
</li>
|
824
|
+
|
825
|
+
<li class="never" data-hits="" data-linenumber="123">
|
826
|
+
|
827
|
+
|
828
|
+
<code class="ruby"> end</code>
|
829
|
+
</li>
|
830
|
+
|
831
|
+
<li class="never" data-hits="" data-linenumber="124">
|
832
|
+
|
833
|
+
|
834
|
+
<code class="ruby"></code>
|
835
|
+
</li>
|
836
|
+
|
837
|
+
<li class="never" data-hits="" data-linenumber="125">
|
778
838
|
|
779
839
|
|
780
840
|
<code class="ruby"> # ActiveSupport #present? and #blank? without patching Object</code>
|
781
841
|
</li>
|
782
842
|
|
783
|
-
<li class="covered" data-hits="1" data-linenumber="
|
843
|
+
<li class="covered" data-hits="1" data-linenumber="126">
|
784
844
|
<span class="hits">1</span>
|
785
845
|
|
786
846
|
<code class="ruby"> def present?(object)</code>
|
787
847
|
</li>
|
788
848
|
|
789
|
-
<li class="covered" data-hits="
|
790
|
-
<span class="hits">
|
849
|
+
<li class="covered" data-hits="24" data-linenumber="127">
|
850
|
+
<span class="hits">24</span>
|
791
851
|
|
792
852
|
<code class="ruby"> !blank?(object)</code>
|
793
853
|
</li>
|
794
854
|
|
795
|
-
<li class="never" data-hits="" data-linenumber="
|
855
|
+
<li class="never" data-hits="" data-linenumber="128">
|
796
856
|
|
797
857
|
|
798
858
|
<code class="ruby"> end</code>
|
799
859
|
</li>
|
800
860
|
|
801
|
-
<li class="never" data-hits="" data-linenumber="
|
861
|
+
<li class="never" data-hits="" data-linenumber="129">
|
802
862
|
|
803
863
|
|
804
864
|
<code class="ruby"></code>
|
805
865
|
</li>
|
806
866
|
|
807
|
-
<li class="covered" data-hits="1" data-linenumber="
|
867
|
+
<li class="covered" data-hits="1" data-linenumber="130">
|
808
868
|
<span class="hits">1</span>
|
809
869
|
|
810
870
|
<code class="ruby"> def blank?(object)</code>
|
811
871
|
</li>
|
812
872
|
|
813
|
-
<li class="covered" data-hits="
|
814
|
-
<span class="hits">
|
873
|
+
<li class="covered" data-hits="24" data-linenumber="131">
|
874
|
+
<span class="hits">24</span>
|
815
875
|
|
816
876
|
<code class="ruby"> object.respond_to?(:empty?) ? object.empty? : !object</code>
|
817
877
|
</li>
|
818
878
|
|
819
|
-
<li class="never" data-hits="" data-linenumber="
|
879
|
+
<li class="never" data-hits="" data-linenumber="132">
|
820
880
|
|
821
881
|
|
822
882
|
<code class="ruby"> end</code>
|
823
883
|
</li>
|
824
884
|
|
825
|
-
<li class="never" data-hits="" data-linenumber="
|
885
|
+
<li class="never" data-hits="" data-linenumber="133">
|
826
886
|
|
827
887
|
|
828
888
|
<code class="ruby"> end</code>
|
829
889
|
</li>
|
830
890
|
|
831
|
-
<li class="never" data-hits="" data-linenumber="
|
891
|
+
<li class="never" data-hits="" data-linenumber="134">
|
832
892
|
|
833
893
|
|
834
894
|
<code class="ruby"></code>
|
835
895
|
</li>
|
836
896
|
|
837
|
-
<li class="covered" data-hits="1" data-linenumber="
|
897
|
+
<li class="covered" data-hits="1" data-linenumber="135">
|
838
898
|
<span class="hits">1</span>
|
839
899
|
|
840
900
|
<code class="ruby"> helpers Param</code>
|
841
901
|
</li>
|
842
902
|
|
843
|
-
<li class="never" data-hits="" data-linenumber="
|
903
|
+
<li class="never" data-hits="" data-linenumber="136">
|
844
904
|
|
845
905
|
|
846
906
|
<code class="ruby">end</code>
|