sinatra-param 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ffa4f732ac04f03dc48517e868e5a867523eb75
4
- data.tar.gz: ab474ce1e1afb21370af3434f3c00fbd24959174
3
+ metadata.gz: 21f8c5cf274d06433fc9c9db6ba610d7778f4e77
4
+ data.tar.gz: b1fad6808c5a4383a0503e7b63bd6342d50b7e9d
5
5
  SHA512:
6
- metadata.gz: d247a854fe31d5e93f1dbb34bdbe645c89206019ee4d5af6f15d89c1455d65867f17a40fd3f7379ad00b2912a66aa1bc8e7a4216295c58f74943e48911e6bb4b
7
- data.tar.gz: 0fdca5b6ebd84db55cd933d77826232ba458e560b2caa5e971ba075eeeb00ffff3304c3c3c0c908dca3caf1ae2b137b8bd0a426f1625b650664219d367ed962d
6
+ metadata.gz: ad633d8cdacce9a83687aa5c0d6036c6bfcfcf6343ec2ea16535d57347b31314d7430b4d392e83f277a4915d088543f1d8f5d4dab84427989d257ae87ce1a7e0
7
+ data.tar.gz: 583990405793ca126bec11afaeae404156be5ea3c878599e1d3ecade175277ed7aaab197eaede9278a60754538a45f83e0912a44459c739696f89a8c3ef33017
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sinatra-param (1.3.1)
4
+ sinatra-param (1.4.0)
5
5
  sinatra (~> 1.3)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -11,6 +11,20 @@ This Sinatra extension takes a first step to solving this problem on the develop
11
11
 
12
12
  > Use `sinatra-param` in combination with [`Rack::PostBodyContentTypeParser` and `Rack::NestedParams`](https://github.com/rack/rack-contrib) to automatically parameterize JSON `POST` bodies and nested parameters.
13
13
 
14
+ ## Install
15
+
16
+ You can install `sinatra-param` from the command line with the following:
17
+
18
+ ```bash
19
+ $ gem install sinatra-param
20
+ ```
21
+
22
+ Alternatively, you can specify `sinatra-param` as a dependency in your `Gemfile` and run `$ bundle install`:
23
+
24
+ ```ruby
25
+ gem "sinatra-param", require: "sinatra/param"
26
+ ```
27
+
14
28
  ## Example
15
29
 
16
30
  ``` ruby
@@ -81,9 +95,9 @@ param :order, String, in: ["ASC", "DESC"], transform: :upcase, default: "ASC"
81
95
  param :offset, Integer, min: 0, transform: lambda {|n| n - (n % 10)}
82
96
  ```
83
97
 
84
- ### Mutual Exclusivity
98
+ ## One Of
85
99
 
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:
100
+ Using `one_of`, routes can specify two or more parameters to be mutually exclusive, and fail if _more than one_ of those parameters is provided:
87
101
 
88
102
  ```ruby
89
103
  param :a, String
@@ -93,6 +107,17 @@ param :c, String
93
107
  one_of :a, :b, :c
94
108
  ```
95
109
 
110
+ ## Any Of
111
+
112
+ Using `any_of`, a route can specify that _at least one of_ two or more parameters are required, and fail if _none of them_ are provided:
113
+
114
+ ```ruby
115
+ param :x, String
116
+ param :y, String
117
+
118
+ any_of :x, :y
119
+ ```
120
+
96
121
  ### Exceptions
97
122
 
98
123
  By default, when a parameter precondition fails, `Sinatra::Param` will `halt 400` with an error message:
@@ -126,12 +151,8 @@ one_of :q, :categories, raise: true
126
151
 
127
152
  ## Contact
128
153
 
129
- Mattt Thompson
130
-
131
- - http://github.com/mattt
132
- - http://twitter.com/mattt
133
- - m@mattt.me
154
+ Mattt Thompson ([@mattt](http://twitter.com/mattt))
134
155
 
135
156
  ## License
136
157
 
137
- sinatra-param is available under the MIT license. See the LICENSE file for more info.
158
+ sinatra-param is released under an MIT license. See LICENSE for more information.
@@ -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="2015-01-22T07:13:54-08:00">2015-01-22T07:13:54-08:00</abbr></div>
17
+ <div class="timestamp">Generated <abbr class="timeago" title="2015-04-21T07:40:09-07:00">2015-04-21T07:40:09-07: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
- 22.3
28
+ 21.4
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>80</b> relevant lines.
36
- <span class="green"><b>80</b> lines covered</span> and
35
+ <b>96</b> relevant lines.
36
+ <span class="green"><b>96</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>136</td>
57
- <td>80</td>
58
- <td>80</td>
56
+ <td>164</td>
57
+ <td>96</td>
58
+ <td>96</td>
59
59
  <td>0</td>
60
- <td>22.3</td>
60
+ <td>21.4</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>80</b> relevant lines.
85
- <span class="green"><b>80</b> lines covered</span> and
84
+ <b>96</b> relevant lines.
85
+ <span class="green"><b>96</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="123" data-linenumber="15">
178
- <span class="hits">123</span>
177
+ <li class="covered" data-hits="147" data-linenumber="15">
178
+ <span class="hits">147</span>
179
179
 
180
180
  <code class="ruby"> name = name.to_s</code>
181
181
  </li>
@@ -186,8 +186,8 @@
186
186
  <code class="ruby"></code>
187
187
  </li>
188
188
 
189
- <li class="covered" data-hits="123" data-linenumber="17">
190
- <span class="hits">123</span>
189
+ <li class="covered" data-hits="147" data-linenumber="17">
190
+ <span class="hits">147</span>
191
191
 
192
192
  <code class="ruby"> return unless params.member?(name) or options[:default] or options[:required]</code>
193
193
  </li>
@@ -198,32 +198,32 @@
198
198
  <code class="ruby"></code>
199
199
  </li>
200
200
 
201
- <li class="covered" data-hits="92" data-linenumber="19">
202
- <span class="hits">92</span>
201
+ <li class="covered" data-hits="102" data-linenumber="19">
202
+ <span class="hits">102</span>
203
203
 
204
204
  <code class="ruby"> begin</code>
205
205
  </li>
206
206
 
207
- <li class="covered" data-hits="92" data-linenumber="20">
208
- <span class="hits">92</span>
207
+ <li class="covered" data-hits="102" data-linenumber="20">
208
+ <span class="hits">102</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="87" data-linenumber="21">
214
- <span class="hits">87</span>
213
+ <li class="covered" data-hits="97" data-linenumber="21">
214
+ <span class="hits">97</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="87" data-linenumber="22">
220
- <span class="hits">87</span>
219
+ <li class="covered" data-hits="97" data-linenumber="22">
220
+ <span class="hits">97</span>
221
221
 
222
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="87" data-linenumber="23">
226
- <span class="hits">87</span>
225
+ <li class="covered" data-hits="97" data-linenumber="23">
226
+ <span class="hits">97</span>
227
227
 
228
228
  <code class="ruby"> validate!(params[name], options)</code>
229
229
  </li>
@@ -267,640 +267,808 @@
267
267
  <li class="covered" data-hits="21" data-linenumber="30">
268
268
  <span class="hits">21</span>
269
269
 
270
- <code class="ruby"> error = &quot;Invalid Parameter: #{name}&quot;</code>
270
+ <code class="ruby"> error = exception.to_s</code>
271
271
  </li>
272
272
 
273
- <li class="covered" data-hits="21" data-linenumber="31">
273
+ <li class="never" data-hits="" data-linenumber="31">
274
+
275
+
276
+ <code class="ruby"></code>
277
+ </li>
278
+
279
+ <li class="covered" data-hits="21" data-linenumber="32">
274
280
  <span class="hits">21</span>
275
281
 
276
282
  <code class="ruby"> if content_type and content_type.match(mime_type(:json))</code>
277
283
  </li>
278
284
 
279
- <li class="covered" data-hits="21" data-linenumber="32">
285
+ <li class="covered" data-hits="21" data-linenumber="33">
280
286
  <span class="hits">21</span>
281
287
 
282
288
  <code class="ruby"> error = {message: error, errors: {name =&gt; exception.message}}.to_json</code>
283
289
  </li>
284
290
 
285
- <li class="never" data-hits="" data-linenumber="33">
291
+ <li class="never" data-hits="" data-linenumber="34">
286
292
 
287
293
 
288
294
  <code class="ruby"> end</code>
289
295
  </li>
290
296
 
291
- <li class="never" data-hits="" data-linenumber="34">
297
+ <li class="never" data-hits="" data-linenumber="35">
292
298
 
293
299
 
294
300
  <code class="ruby"></code>
295
301
  </li>
296
302
 
297
- <li class="covered" data-hits="21" data-linenumber="35">
303
+ <li class="covered" data-hits="21" data-linenumber="36">
298
304
  <span class="hits">21</span>
299
305
 
300
306
  <code class="ruby"> halt 400, error</code>
301
307
  </li>
302
308
 
303
- <li class="never" data-hits="" data-linenumber="36">
309
+ <li class="never" data-hits="" data-linenumber="37">
304
310
 
305
311
 
306
312
  <code class="ruby"> end</code>
307
313
  </li>
308
314
 
309
- <li class="never" data-hits="" data-linenumber="37">
315
+ <li class="never" data-hits="" data-linenumber="38">
310
316
 
311
317
 
312
318
  <code class="ruby"> end</code>
313
319
  </li>
314
320
 
315
- <li class="never" data-hits="" data-linenumber="38">
321
+ <li class="never" data-hits="" data-linenumber="39">
316
322
 
317
323
 
318
324
  <code class="ruby"></code>
319
325
  </li>
320
326
 
321
- <li class="covered" data-hits="1" data-linenumber="39">
327
+ <li class="covered" data-hits="1" data-linenumber="40">
322
328
  <span class="hits">1</span>
323
329
 
324
330
  <code class="ruby"> def one_of(*args)</code>
325
331
  </li>
326
332
 
327
- <li class="covered" data-hits="17" data-linenumber="40">
333
+ <li class="covered" data-hits="17" data-linenumber="41">
328
334
  <span class="hits">17</span>
329
335
 
330
336
  <code class="ruby"> options = args.last.is_a?(Hash) ? args.pop : {}</code>
331
337
  </li>
332
338
 
333
- <li class="covered" data-hits="17" data-linenumber="41">
339
+ <li class="covered" data-hits="17" data-linenumber="42">
334
340
  <span class="hits">17</span>
335
341
 
336
342
  <code class="ruby"> names = args.collect(&amp;:to_s)</code>
337
343
  </li>
338
344
 
339
- <li class="never" data-hits="" data-linenumber="42">
345
+ <li class="never" data-hits="" data-linenumber="43">
340
346
 
341
347
 
342
348
  <code class="ruby"></code>
343
349
  </li>
344
350
 
345
- <li class="covered" data-hits="17" data-linenumber="43">
351
+ <li class="covered" data-hits="17" data-linenumber="44">
346
352
  <span class="hits">17</span>
347
353
 
348
354
  <code class="ruby"> return unless names.length &gt;= 2</code>
349
355
  </li>
350
356
 
351
- <li class="never" data-hits="" data-linenumber="44">
357
+ <li class="never" data-hits="" data-linenumber="45">
352
358
 
353
359
 
354
360
  <code class="ruby"></code>
355
361
  </li>
356
362
 
357
- <li class="covered" data-hits="13" data-linenumber="45">
363
+ <li class="covered" data-hits="13" data-linenumber="46">
358
364
  <span class="hits">13</span>
359
365
 
360
366
  <code class="ruby"> begin</code>
361
367
  </li>
362
368
 
363
- <li class="covered" data-hits="13" data-linenumber="46">
369
+ <li class="covered" data-hits="13" data-linenumber="47">
364
370
  <span class="hits">13</span>
365
371
 
366
372
  <code class="ruby"> validate_one_of!(params, names, options)</code>
367
373
  </li>
368
374
 
369
- <li class="covered" data-hits="5" data-linenumber="47">
375
+ <li class="covered" data-hits="5" data-linenumber="48">
370
376
  <span class="hits">5</span>
371
377
 
372
378
  <code class="ruby"> rescue InvalidParameterError =&gt; exception</code>
373
379
  </li>
374
380
 
375
- <li class="covered" data-hits="5" data-linenumber="48">
381
+ <li class="covered" data-hits="5" data-linenumber="49">
376
382
  <span class="hits">5</span>
377
383
 
378
384
  <code class="ruby"> if options[:raise] or (settings.raise_sinatra_param_exceptions rescue false)</code>
379
385
  </li>
380
386
 
381
- <li class="covered" data-hits="1" data-linenumber="49">
387
+ <li class="covered" data-hits="1" data-linenumber="50">
382
388
  <span class="hits">1</span>
383
389
 
384
390
  <code class="ruby"> exception.param, exception.options = names, options</code>
385
391
  </li>
386
392
 
387
- <li class="covered" data-hits="1" data-linenumber="50">
393
+ <li class="covered" data-hits="1" data-linenumber="51">
388
394
  <span class="hits">1</span>
389
395
 
390
396
  <code class="ruby"> raise exception</code>
391
397
  </li>
392
398
 
393
- <li class="never" data-hits="" data-linenumber="51">
399
+ <li class="never" data-hits="" data-linenumber="52">
394
400
 
395
401
 
396
402
  <code class="ruby"> end</code>
397
403
  </li>
398
404
 
399
- <li class="never" data-hits="" data-linenumber="52">
405
+ <li class="never" data-hits="" data-linenumber="53">
400
406
 
401
407
 
402
408
  <code class="ruby"></code>
403
409
  </li>
404
410
 
405
- <li class="covered" data-hits="4" data-linenumber="53">
411
+ <li class="covered" data-hits="4" data-linenumber="54">
406
412
  <span class="hits">4</span>
407
413
 
408
- <code class="ruby"> error = &quot;Parameters #{names.join(&#39;, &#39;)} are mutually exclusive&quot;</code>
414
+ <code class="ruby"> error = &quot;Invalid parameters [#{names.join(&#39;, &#39;)}]&quot;</code>
409
415
  </li>
410
416
 
411
- <li class="covered" data-hits="4" data-linenumber="54">
417
+ <li class="covered" data-hits="4" data-linenumber="55">
412
418
  <span class="hits">4</span>
413
419
 
414
420
  <code class="ruby"> if content_type and content_type.match(mime_type(:json))</code>
415
421
  </li>
416
422
 
417
- <li class="covered" data-hits="4" data-linenumber="55">
423
+ <li class="covered" data-hits="4" data-linenumber="56">
418
424
  <span class="hits">4</span>
419
425
 
420
426
  <code class="ruby"> error = {message: error, errors: {names =&gt; exception.message}}.to_json</code>
421
427
  </li>
422
428
 
423
- <li class="never" data-hits="" data-linenumber="56">
429
+ <li class="never" data-hits="" data-linenumber="57">
424
430
 
425
431
 
426
432
  <code class="ruby"> end</code>
427
433
  </li>
428
434
 
429
- <li class="never" data-hits="" data-linenumber="57">
435
+ <li class="never" data-hits="" data-linenumber="58">
430
436
 
431
437
 
432
438
  <code class="ruby"></code>
433
439
  </li>
434
440
 
435
- <li class="covered" data-hits="4" data-linenumber="58">
441
+ <li class="covered" data-hits="4" data-linenumber="59">
436
442
  <span class="hits">4</span>
437
443
 
438
444
  <code class="ruby"> halt 400, error</code>
439
445
  </li>
440
446
 
441
- <li class="never" data-hits="" data-linenumber="59">
447
+ <li class="never" data-hits="" data-linenumber="60">
442
448
 
443
449
 
444
450
  <code class="ruby"> end</code>
445
451
  </li>
446
452
 
447
- <li class="never" data-hits="" data-linenumber="60">
453
+ <li class="never" data-hits="" data-linenumber="61">
448
454
 
449
455
 
450
456
  <code class="ruby"> end</code>
451
457
  </li>
452
458
 
453
- <li class="never" data-hits="" data-linenumber="61">
459
+ <li class="never" data-hits="" data-linenumber="62">
460
+
461
+
462
+ <code class="ruby"></code>
463
+ </li>
464
+
465
+ <li class="covered" data-hits="1" data-linenumber="63">
466
+ <span class="hits">1</span>
467
+
468
+ <code class="ruby"> def any_of(*args)</code>
469
+ </li>
470
+
471
+ <li class="covered" data-hits="8" data-linenumber="64">
472
+ <span class="hits">8</span>
473
+
474
+ <code class="ruby"> options = args.last.is_a?(Hash) ? args.pop : {}</code>
475
+ </li>
476
+
477
+ <li class="covered" data-hits="8" data-linenumber="65">
478
+ <span class="hits">8</span>
479
+
480
+ <code class="ruby"> names = args.collect(&amp;:to_s)</code>
481
+ </li>
482
+
483
+ <li class="never" data-hits="" data-linenumber="66">
484
+
485
+
486
+ <code class="ruby"></code>
487
+ </li>
488
+
489
+ <li class="covered" data-hits="8" data-linenumber="67">
490
+ <span class="hits">8</span>
491
+
492
+ <code class="ruby"> return unless names.length &gt;= 2</code>
493
+ </li>
494
+
495
+ <li class="never" data-hits="" data-linenumber="68">
496
+
497
+
498
+ <code class="ruby"></code>
499
+ </li>
500
+
501
+ <li class="covered" data-hits="8" data-linenumber="69">
502
+ <span class="hits">8</span>
503
+
504
+ <code class="ruby"> begin</code>
505
+ </li>
506
+
507
+ <li class="covered" data-hits="8" data-linenumber="70">
508
+ <span class="hits">8</span>
509
+
510
+ <code class="ruby"> validate_any_of!(params, names, options)</code>
511
+ </li>
512
+
513
+ <li class="covered" data-hits="2" data-linenumber="71">
514
+ <span class="hits">2</span>
515
+
516
+ <code class="ruby"> rescue InvalidParameterError =&gt; exception</code>
517
+ </li>
518
+
519
+ <li class="covered" data-hits="2" data-linenumber="72">
520
+ <span class="hits">2</span>
521
+
522
+ <code class="ruby"> if options[:raise] or (settings.raise_sinatra_param_exceptions rescue false)</code>
523
+ </li>
524
+
525
+ <li class="covered" data-hits="1" data-linenumber="73">
526
+ <span class="hits">1</span>
527
+
528
+ <code class="ruby"> exception.param, exception.options = names, options</code>
529
+ </li>
530
+
531
+ <li class="covered" data-hits="1" data-linenumber="74">
532
+ <span class="hits">1</span>
533
+
534
+ <code class="ruby"> raise exception</code>
535
+ </li>
536
+
537
+ <li class="never" data-hits="" data-linenumber="75">
538
+
539
+
540
+ <code class="ruby"> end</code>
541
+ </li>
542
+
543
+ <li class="never" data-hits="" data-linenumber="76">
544
+
545
+
546
+ <code class="ruby"></code>
547
+ </li>
548
+
549
+ <li class="covered" data-hits="1" data-linenumber="77">
550
+ <span class="hits">1</span>
551
+
552
+ <code class="ruby"> error = &quot;Invalid parameters [#{names.join(&#39;, &#39;)}]&quot;</code>
553
+ </li>
554
+
555
+ <li class="covered" data-hits="1" data-linenumber="78">
556
+ <span class="hits">1</span>
557
+
558
+ <code class="ruby"> if content_type and content_type.match(mime_type(:json))</code>
559
+ </li>
560
+
561
+ <li class="covered" data-hits="1" data-linenumber="79">
562
+ <span class="hits">1</span>
563
+
564
+ <code class="ruby"> error = {message: error, errors: {names =&gt; exception.message}}.to_json</code>
565
+ </li>
566
+
567
+ <li class="never" data-hits="" data-linenumber="80">
568
+
569
+
570
+ <code class="ruby"> end</code>
571
+ </li>
572
+
573
+ <li class="never" data-hits="" data-linenumber="81">
574
+
575
+
576
+ <code class="ruby"></code>
577
+ </li>
578
+
579
+ <li class="covered" data-hits="1" data-linenumber="82">
580
+ <span class="hits">1</span>
581
+
582
+ <code class="ruby"> halt 400, error</code>
583
+ </li>
584
+
585
+ <li class="never" data-hits="" data-linenumber="83">
586
+
587
+
588
+ <code class="ruby"> end</code>
589
+ </li>
590
+
591
+ <li class="never" data-hits="" data-linenumber="84">
592
+
593
+
594
+ <code class="ruby"> end</code>
595
+ </li>
596
+
597
+ <li class="never" data-hits="" data-linenumber="85">
454
598
 
455
599
 
456
600
  <code class="ruby"></code>
457
601
  </li>
458
602
 
459
- <li class="covered" data-hits="1" data-linenumber="62">
603
+ <li class="covered" data-hits="1" data-linenumber="86">
460
604
  <span class="hits">1</span>
461
605
 
462
606
  <code class="ruby"> private</code>
463
607
  </li>
464
608
 
465
- <li class="never" data-hits="" data-linenumber="63">
609
+ <li class="never" data-hits="" data-linenumber="87">
466
610
 
467
611
 
468
612
  <code class="ruby"></code>
469
613
  </li>
470
614
 
471
- <li class="covered" data-hits="1" data-linenumber="64">
615
+ <li class="covered" data-hits="1" data-linenumber="88">
472
616
  <span class="hits">1</span>
473
617
 
474
618
  <code class="ruby"> def coerce(param, type, options = {})</code>
475
619
  </li>
476
620
 
477
- <li class="covered" data-hits="92" data-linenumber="65">
478
- <span class="hits">92</span>
621
+ <li class="covered" data-hits="102" data-linenumber="89">
622
+ <span class="hits">102</span>
479
623
 
480
624
  <code class="ruby"> begin</code>
481
625
  </li>
482
626
 
483
- <li class="covered" data-hits="92" data-linenumber="66">
484
- <span class="hits">92</span>
627
+ <li class="covered" data-hits="102" data-linenumber="90">
628
+ <span class="hits">102</span>
485
629
 
486
630
  <code class="ruby"> return nil if param.nil?</code>
487
631
  </li>
488
632
 
489
- <li class="covered" data-hits="85" data-linenumber="67">
490
- <span class="hits">85</span>
633
+ <li class="covered" data-hits="95" data-linenumber="91">
634
+ <span class="hits">95</span>
491
635
 
492
636
  <code class="ruby"> return param if (param.is_a?(type) rescue false)</code>
493
637
  </li>
494
638
 
495
- <li class="covered" data-hits="46" data-linenumber="68">
639
+ <li class="covered" data-hits="46" data-linenumber="92">
496
640
  <span class="hits">46</span>
497
641
 
498
642
  <code class="ruby"> return Integer(param) if type == Integer</code>
499
643
  </li>
500
644
 
501
- <li class="covered" data-hits="35" data-linenumber="69">
645
+ <li class="covered" data-hits="35" data-linenumber="93">
502
646
  <span class="hits">35</span>
503
647
 
504
648
  <code class="ruby"> return Float(param) if type == Float</code>
505
649
  </li>
506
650
 
507
- <li class="covered" data-hits="33" data-linenumber="70">
651
+ <li class="covered" data-hits="33" data-linenumber="94">
508
652
  <span class="hits">33</span>
509
653
 
510
654
  <code class="ruby"> return String(param) if type == String</code>
511
655
  </li>
512
656
 
513
- <li class="covered" data-hits="32" data-linenumber="71">
657
+ <li class="covered" data-hits="32" data-linenumber="95">
514
658
  <span class="hits">32</span>
515
659
 
516
660
  <code class="ruby"> return Date.parse(param) if type == Date</code>
517
661
  </li>
518
662
 
519
- <li class="covered" data-hits="30" data-linenumber="72">
663
+ <li class="covered" data-hits="30" data-linenumber="96">
520
664
  <span class="hits">30</span>
521
665
 
522
666
  <code class="ruby"> return Time.parse(param) if type == Time</code>
523
667
  </li>
524
668
 
525
- <li class="covered" data-hits="28" data-linenumber="73">
669
+ <li class="covered" data-hits="28" data-linenumber="97">
526
670
  <span class="hits">28</span>
527
671
 
528
672
  <code class="ruby"> return DateTime.parse(param) if type == DateTime</code>
529
673
  </li>
530
674
 
531
- <li class="covered" data-hits="26" data-linenumber="74">
675
+ <li class="covered" data-hits="26" data-linenumber="98">
532
676
  <span class="hits">26</span>
533
677
 
534
678
  <code class="ruby"> return Array(param.split(options[:delimiter] || &quot;,&quot;)) if type == Array</code>
535
679
  </li>
536
680
 
537
- <li class="covered" data-hits="25" data-linenumber="75">
681
+ <li class="covered" data-hits="25" data-linenumber="99">
538
682
  <span class="hits">25</span>
539
683
 
540
684
  <code class="ruby"> return Hash[param.split(options[:delimiter] || &quot;,&quot;).map{|c| c.split(options[:separator] || &quot;:&quot;)}] if type == Hash</code>
541
685
  </li>
542
686
 
543
- <li class="covered" data-hits="21" data-linenumber="76">
687
+ <li class="covered" data-hits="21" data-linenumber="100">
544
688
  <span class="hits">21</span>
545
689
 
546
690
  <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>
547
691
  </li>
548
692
 
549
- <li class="never" data-hits="" data-linenumber="77">
693
+ <li class="never" data-hits="" data-linenumber="101">
550
694
 
551
695
 
552
696
  <code class="ruby"> return nil</code>
553
697
  </li>
554
698
 
555
- <li class="covered" data-hits="5" data-linenumber="78">
699
+ <li class="covered" data-hits="5" data-linenumber="102">
556
700
  <span class="hits">5</span>
557
701
 
558
702
  <code class="ruby"> rescue ArgumentError</code>
559
703
  </li>
560
704
 
561
- <li class="covered" data-hits="5" data-linenumber="79">
705
+ <li class="covered" data-hits="5" data-linenumber="103">
562
706
  <span class="hits">5</span>
563
707
 
564
708
  <code class="ruby"> raise InvalidParameterError, &quot;&#39;#{param}&#39; is not a valid #{type}&quot;</code>
565
709
  </li>
566
710
 
567
- <li class="never" data-hits="" data-linenumber="80">
711
+ <li class="never" data-hits="" data-linenumber="104">
568
712
 
569
713
 
570
714
  <code class="ruby"> end</code>
571
715
  </li>
572
716
 
573
- <li class="never" data-hits="" data-linenumber="81">
717
+ <li class="never" data-hits="" data-linenumber="105">
574
718
 
575
719
 
576
720
  <code class="ruby"> end</code>
577
721
  </li>
578
722
 
579
- <li class="never" data-hits="" data-linenumber="82">
723
+ <li class="never" data-hits="" data-linenumber="106">
580
724
 
581
725
 
582
726
  <code class="ruby"></code>
583
727
  </li>
584
728
 
585
- <li class="covered" data-hits="1" data-linenumber="83">
729
+ <li class="covered" data-hits="1" data-linenumber="107">
586
730
  <span class="hits">1</span>
587
731
 
588
732
  <code class="ruby"> def validate!(param, options)</code>
589
733
  </li>
590
734
 
591
- <li class="covered" data-hits="87" data-linenumber="84">
592
- <span class="hits">87</span>
735
+ <li class="covered" data-hits="97" data-linenumber="108">
736
+ <span class="hits">97</span>
593
737
 
594
738
  <code class="ruby"> options.each do |key, value|</code>
595
739
  </li>
596
740
 
597
- <li class="covered" data-hits="45" data-linenumber="85">
741
+ <li class="covered" data-hits="45" data-linenumber="109">
598
742
  <span class="hits">45</span>
599
743
 
600
744
  <code class="ruby"> case key</code>
601
745
  </li>
602
746
 
603
- <li class="never" data-hits="" data-linenumber="86">
747
+ <li class="never" data-hits="" data-linenumber="110">
604
748
 
605
749
 
606
750
  <code class="ruby"> when :required</code>
607
751
  </li>
608
752
 
609
- <li class="covered" data-hits="5" data-linenumber="87">
753
+ <li class="covered" data-hits="5" data-linenumber="111">
610
754
  <span class="hits">5</span>
611
755
 
612
756
  <code class="ruby"> raise InvalidParameterError, &quot;Parameter is required&quot; if value &amp;&amp; param.nil?</code>
613
757
  </li>
614
758
 
615
- <li class="never" data-hits="" data-linenumber="88">
759
+ <li class="never" data-hits="" data-linenumber="112">
616
760
 
617
761
 
618
762
  <code class="ruby"> when :blank</code>
619
763
  </li>
620
764
 
621
- <li class="never" data-hits="" data-linenumber="89">
765
+ <li class="never" data-hits="" data-linenumber="113">
622
766
 
623
767
 
624
768
  <code class="ruby"> raise InvalidParameterError, &quot;Parameter cannot be blank&quot; if !value &amp;&amp; case param</code>
625
769
  </li>
626
770
 
627
- <li class="never" data-hits="" data-linenumber="90">
771
+ <li class="never" data-hits="" data-linenumber="114">
628
772
 
629
773
 
630
- <code class="ruby"> when String</code>
774
+ <code class="ruby"> when String</code>
631
775
  </li>
632
776
 
633
- <li class="covered" data-hits="1" data-linenumber="91">
777
+ <li class="covered" data-hits="1" data-linenumber="115">
634
778
  <span class="hits">1</span>
635
779
 
636
- <code class="ruby"> !(/\S/ === param)</code>
780
+ <code class="ruby"> !(/\S/ === param)</code>
637
781
  </li>
638
782
 
639
- <li class="never" data-hits="" data-linenumber="92">
783
+ <li class="never" data-hits="" data-linenumber="116">
640
784
 
641
785
 
642
- <code class="ruby"> when Array, Hash</code>
786
+ <code class="ruby"> when Array, Hash</code>
643
787
  </li>
644
788
 
645
- <li class="covered" data-hits="2" data-linenumber="93">
789
+ <li class="covered" data-hits="2" data-linenumber="117">
646
790
  <span class="hits">2</span>
647
791
 
648
- <code class="ruby"> param.empty?</code>
792
+ <code class="ruby"> param.empty?</code>
649
793
  </li>
650
794
 
651
- <li class="never" data-hits="" data-linenumber="94">
795
+ <li class="never" data-hits="" data-linenumber="118">
652
796
 
653
797
 
654
- <code class="ruby"> else</code>
798
+ <code class="ruby"> else</code>
655
799
  </li>
656
800
 
657
- <li class="covered" data-hits="1" data-linenumber="95">
801
+ <li class="covered" data-hits="1" data-linenumber="119">
658
802
  <span class="hits">1</span>
659
803
 
660
- <code class="ruby"> param.nil?</code>
804
+ <code class="ruby"> param.nil?</code>
661
805
  </li>
662
806
 
663
- <li class="covered" data-hits="5" data-linenumber="96">
807
+ <li class="covered" data-hits="5" data-linenumber="120">
664
808
  <span class="hits">5</span>
665
809
 
666
- <code class="ruby"> end</code>
810
+ <code class="ruby"> end</code>
667
811
  </li>
668
812
 
669
- <li class="never" data-hits="" data-linenumber="97">
813
+ <li class="never" data-hits="" data-linenumber="121">
670
814
 
671
815
 
672
816
  <code class="ruby"> when :format</code>
673
817
  </li>
674
818
 
675
- <li class="covered" data-hits="3" data-linenumber="98">
819
+ <li class="covered" data-hits="3" data-linenumber="122">
676
820
  <span class="hits">3</span>
677
821
 
678
822
  <code class="ruby"> raise InvalidParameterError, &quot;Parameter must be a string if using the format validation&quot; unless param.kind_of?(String)</code>
679
823
  </li>
680
824
 
681
- <li class="covered" data-hits="2" data-linenumber="99">
825
+ <li class="covered" data-hits="2" data-linenumber="123">
682
826
  <span class="hits">2</span>
683
827
 
684
828
  <code class="ruby"> raise InvalidParameterError, &quot;Parameter must match format #{value}&quot; unless param =~ value</code>
685
829
  </li>
686
830
 
687
- <li class="never" data-hits="" data-linenumber="100">
831
+ <li class="never" data-hits="" data-linenumber="124">
688
832
 
689
833
 
690
834
  <code class="ruby"> when :is</code>
691
835
  </li>
692
836
 
693
- <li class="covered" data-hits="2" data-linenumber="101">
837
+ <li class="covered" data-hits="2" data-linenumber="125">
694
838
  <span class="hits">2</span>
695
839
 
696
840
  <code class="ruby"> raise InvalidParameterError, &quot;Parameter must be #{value}&quot; unless param === value</code>
697
841
  </li>
698
842
 
699
- <li class="never" data-hits="" data-linenumber="102">
843
+ <li class="never" data-hits="" data-linenumber="126">
700
844
 
701
845
 
702
846
  <code class="ruby"> when :in, :within, :range</code>
703
847
  </li>
704
848
 
705
- <li class="never" data-hits="" data-linenumber="103">
849
+ <li class="never" data-hits="" data-linenumber="127">
706
850
 
707
851
 
708
852
  <code class="ruby"> raise InvalidParameterError, &quot;Parameter must be within #{value}&quot; unless param.nil? || case value</code>
709
853
  </li>
710
854
 
711
- <li class="never" data-hits="" data-linenumber="104">
855
+ <li class="never" data-hits="" data-linenumber="128">
712
856
 
713
857
 
714
- <code class="ruby"> when Range</code>
858
+ <code class="ruby"> when Range</code>
715
859
  </li>
716
860
 
717
- <li class="covered" data-hits="4" data-linenumber="105">
861
+ <li class="covered" data-hits="4" data-linenumber="129">
718
862
  <span class="hits">4</span>
719
863
 
720
- <code class="ruby"> value.include?(param)</code>
864
+ <code class="ruby"> value.include?(param)</code>
721
865
  </li>
722
866
 
723
- <li class="never" data-hits="" data-linenumber="106">
867
+ <li class="never" data-hits="" data-linenumber="130">
724
868
 
725
869
 
726
- <code class="ruby"> else</code>
870
+ <code class="ruby"> else</code>
727
871
  </li>
728
872
 
729
- <li class="covered" data-hits="2" data-linenumber="107">
873
+ <li class="covered" data-hits="2" data-linenumber="131">
730
874
  <span class="hits">2</span>
731
875
 
732
- <code class="ruby"> Array(value).include?(param)</code>
876
+ <code class="ruby"> Array(value).include?(param)</code>
733
877
  </li>
734
878
 
735
- <li class="covered" data-hits="6" data-linenumber="108">
879
+ <li class="covered" data-hits="6" data-linenumber="132">
736
880
  <span class="hits">6</span>
737
881
 
738
- <code class="ruby"> end</code>
882
+ <code class="ruby"> end</code>
739
883
  </li>
740
884
 
741
- <li class="never" data-hits="" data-linenumber="109">
885
+ <li class="never" data-hits="" data-linenumber="133">
742
886
 
743
887
 
744
888
  <code class="ruby"> when :min</code>
745
889
  </li>
746
890
 
747
- <li class="covered" data-hits="2" data-linenumber="110">
891
+ <li class="covered" data-hits="2" data-linenumber="134">
748
892
  <span class="hits">2</span>
749
893
 
750
894
  <code class="ruby"> raise InvalidParameterError, &quot;Parameter cannot be less than #{value}&quot; unless param.nil? || value &lt;= param</code>
751
895
  </li>
752
896
 
753
- <li class="never" data-hits="" data-linenumber="111">
897
+ <li class="never" data-hits="" data-linenumber="135">
754
898
 
755
899
 
756
900
  <code class="ruby"> when :max</code>
757
901
  </li>
758
902
 
759
- <li class="covered" data-hits="2" data-linenumber="112">
903
+ <li class="covered" data-hits="2" data-linenumber="136">
760
904
  <span class="hits">2</span>
761
905
 
762
906
  <code class="ruby"> raise InvalidParameterError, &quot;Parameter cannot be greater than #{value}&quot; unless param.nil? || value &gt;= param</code>
763
907
  </li>
764
908
 
765
- <li class="never" data-hits="" data-linenumber="113">
909
+ <li class="never" data-hits="" data-linenumber="137">
766
910
 
767
911
 
768
912
  <code class="ruby"> when :min_length</code>
769
913
  </li>
770
914
 
771
- <li class="covered" data-hits="1" data-linenumber="114">
915
+ <li class="covered" data-hits="1" data-linenumber="138">
772
916
  <span class="hits">1</span>
773
917
 
774
918
  <code class="ruby"> raise InvalidParameterError, &quot;Parameter cannot have length less than #{value}&quot; unless param.nil? || value &lt;= param.length</code>
775
919
  </li>
776
920
 
777
- <li class="never" data-hits="" data-linenumber="115">
921
+ <li class="never" data-hits="" data-linenumber="139">
778
922
 
779
923
 
780
924
  <code class="ruby"> when :max_length</code>
781
925
  </li>
782
926
 
783
- <li class="covered" data-hits="3" data-linenumber="116">
927
+ <li class="covered" data-hits="3" data-linenumber="140">
784
928
  <span class="hits">3</span>
785
929
 
786
930
  <code class="ruby"> raise InvalidParameterError, &quot;Parameter cannot have length greater than #{value}&quot; unless param.nil? || value &gt;= param.length</code>
787
931
  </li>
788
932
 
789
- <li class="never" data-hits="" data-linenumber="117">
933
+ <li class="never" data-hits="" data-linenumber="141">
790
934
 
791
935
 
792
936
  <code class="ruby"> end</code>
793
937
  </li>
794
938
 
795
- <li class="never" data-hits="" data-linenumber="118">
939
+ <li class="never" data-hits="" data-linenumber="142">
796
940
 
797
941
 
798
942
  <code class="ruby"> end</code>
799
943
  </li>
800
944
 
801
- <li class="never" data-hits="" data-linenumber="119">
945
+ <li class="never" data-hits="" data-linenumber="143">
802
946
 
803
947
 
804
948
  <code class="ruby"> end</code>
805
949
  </li>
806
950
 
807
- <li class="never" data-hits="" data-linenumber="120">
951
+ <li class="never" data-hits="" data-linenumber="144">
808
952
 
809
953
 
810
954
  <code class="ruby"></code>
811
955
  </li>
812
956
 
813
- <li class="covered" data-hits="1" data-linenumber="121">
957
+ <li class="covered" data-hits="1" data-linenumber="145">
814
958
  <span class="hits">1</span>
815
959
 
816
960
  <code class="ruby"> def validate_one_of!(params, names, options)</code>
817
961
  </li>
818
962
 
819
- <li class="covered" data-hits="47" data-linenumber="122">
963
+ <li class="covered" data-hits="47" data-linenumber="146">
820
964
  <span class="hits">47</span>
821
965
 
822
- <code class="ruby"> raise InvalidParameterError, &quot;Parameters #{names.join(&#39;, &#39;)} are mutually exclusive&quot; if names.count{|name| present?(params[name])} &gt; 1</code>
966
+ <code class="ruby"> raise InvalidParameterError, &quot;Only one of [#{names.join(&#39;, &#39;)}] is allowed&quot; if names.count{|name| present?(params[name])} &gt; 1</code>
823
967
  </li>
824
968
 
825
- <li class="never" data-hits="" data-linenumber="123">
969
+ <li class="never" data-hits="" data-linenumber="147">
826
970
 
827
971
 
828
972
  <code class="ruby"> end</code>
829
973
  </li>
830
974
 
831
- <li class="never" data-hits="" data-linenumber="124">
975
+ <li class="never" data-hits="" data-linenumber="148">
976
+
977
+
978
+ <code class="ruby"></code>
979
+ </li>
980
+
981
+ <li class="covered" data-hits="1" data-linenumber="149">
982
+ <span class="hits">1</span>
983
+
984
+ <code class="ruby"> def validate_any_of!(params, names, options)</code>
985
+ </li>
986
+
987
+ <li class="covered" data-hits="32" data-linenumber="150">
988
+ <span class="hits">32</span>
989
+
990
+ <code class="ruby"> raise InvalidParameterError, &quot;One of parameters [#{names.join(&#39;, &#39;)}] is required&quot; if names.count{|name| present?(params[name])} &lt; 1</code>
991
+ </li>
992
+
993
+ <li class="never" data-hits="" data-linenumber="151">
994
+
995
+
996
+ <code class="ruby"> end</code>
997
+ </li>
998
+
999
+ <li class="never" data-hits="" data-linenumber="152">
832
1000
 
833
1001
 
834
1002
  <code class="ruby"></code>
835
1003
  </li>
836
1004
 
837
- <li class="never" data-hits="" data-linenumber="125">
1005
+ <li class="never" data-hits="" data-linenumber="153">
838
1006
 
839
1007
 
840
1008
  <code class="ruby"> # ActiveSupport #present? and #blank? without patching Object</code>
841
1009
  </li>
842
1010
 
843
- <li class="covered" data-hits="1" data-linenumber="126">
1011
+ <li class="covered" data-hits="1" data-linenumber="154">
844
1012
  <span class="hits">1</span>
845
1013
 
846
1014
  <code class="ruby"> def present?(object)</code>
847
1015
  </li>
848
1016
 
849
- <li class="covered" data-hits="34" data-linenumber="127">
850
- <span class="hits">34</span>
1017
+ <li class="covered" data-hits="58" data-linenumber="155">
1018
+ <span class="hits">58</span>
851
1019
 
852
1020
  <code class="ruby"> !blank?(object)</code>
853
1021
  </li>
854
1022
 
855
- <li class="never" data-hits="" data-linenumber="128">
1023
+ <li class="never" data-hits="" data-linenumber="156">
856
1024
 
857
1025
 
858
1026
  <code class="ruby"> end</code>
859
1027
  </li>
860
1028
 
861
- <li class="never" data-hits="" data-linenumber="129">
1029
+ <li class="never" data-hits="" data-linenumber="157">
862
1030
 
863
1031
 
864
1032
  <code class="ruby"></code>
865
1033
  </li>
866
1034
 
867
- <li class="covered" data-hits="1" data-linenumber="130">
1035
+ <li class="covered" data-hits="1" data-linenumber="158">
868
1036
  <span class="hits">1</span>
869
1037
 
870
1038
  <code class="ruby"> def blank?(object)</code>
871
1039
  </li>
872
1040
 
873
- <li class="covered" data-hits="34" data-linenumber="131">
874
- <span class="hits">34</span>
1041
+ <li class="covered" data-hits="58" data-linenumber="159">
1042
+ <span class="hits">58</span>
875
1043
 
876
1044
  <code class="ruby"> object.respond_to?(:empty?) ? object.empty? : !object</code>
877
1045
  </li>
878
1046
 
879
- <li class="never" data-hits="" data-linenumber="132">
1047
+ <li class="never" data-hits="" data-linenumber="160">
880
1048
 
881
1049
 
882
1050
  <code class="ruby"> end</code>
883
1051
  </li>
884
1052
 
885
- <li class="never" data-hits="" data-linenumber="133">
1053
+ <li class="never" data-hits="" data-linenumber="161">
886
1054
 
887
1055
 
888
1056
  <code class="ruby"> end</code>
889
1057
  </li>
890
1058
 
891
- <li class="never" data-hits="" data-linenumber="134">
1059
+ <li class="never" data-hits="" data-linenumber="162">
892
1060
 
893
1061
 
894
1062
  <code class="ruby"></code>
895
1063
  </li>
896
1064
 
897
- <li class="covered" data-hits="1" data-linenumber="135">
1065
+ <li class="covered" data-hits="1" data-linenumber="163">
898
1066
  <span class="hits">1</span>
899
1067
 
900
1068
  <code class="ruby"> helpers Param</code>
901
1069
  </li>
902
1070
 
903
- <li class="never" data-hits="" data-linenumber="136">
1071
+ <li class="never" data-hits="" data-linenumber="164">
904
1072
 
905
1073
 
906
1074
  <code class="ruby">end</code>