sinatra-param 1.3.0 → 1.3.1
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/Rakefile +8 -0
- data/coverage/index.html +54 -54
- data/lib/sinatra/param.rb +1 -1
- data/lib/sinatra/param/version.rb +1 -1
- data/sinatra-param-1.3.0.gem +0 -0
- data/sinatra-param.gemspec +1 -1
- data/spec/dummy/app.rb +26 -2
- data/spec/parameter_exclusivity_spec.rb +21 -8
- data/spec/parameter_raise_spec.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ffa4f732ac04f03dc48517e868e5a867523eb75
|
4
|
+
data.tar.gz: ab474ce1e1afb21370af3434f3c00fbd24959174
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d247a854fe31d5e93f1dbb34bdbe645c89206019ee4d5af6f15d89c1455d65867f17a40fd3f7379ad00b2912a66aa1bc8e7a4216295c58f74943e48911e6bb4b
|
7
|
+
data.tar.gz: 0fdca5b6ebd84db55cd933d77826232ba458e560b2caa5e971ba075eeeb00ffff3304c3c3c0c908dca3caf1ae2b137b8bd0a426f1625b650664219d367ed962d
|
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -8,3 +8,11 @@ task :build => "#{gemspec.full_name}.gem"
|
|
8
8
|
file "#{gemspec.full_name}.gem" => gemspec.files + ["sinatra-param.gemspec"] do
|
9
9
|
system "gem build sinatra-param.gemspec"
|
10
10
|
end
|
11
|
+
|
12
|
+
begin
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
RSpec::Core::RakeTask.new(:spec)
|
15
|
+
|
16
|
+
task :default => :spec
|
17
|
+
rescue LoadError
|
18
|
+
end
|
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="2015-01-
|
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>
|
18
18
|
<ul class="group_tabs"></ul>
|
19
19
|
|
20
20
|
<div id="content">
|
@@ -25,7 +25,7 @@
|
|
25
25
|
covered at
|
26
26
|
<span class="covered_strength">
|
27
27
|
<span class="green">
|
28
|
-
|
28
|
+
22.3
|
29
29
|
</span>
|
30
30
|
</span> hits/line)
|
31
31
|
</h2>
|
@@ -57,7 +57,7 @@
|
|
57
57
|
<td>80</td>
|
58
58
|
<td>80</td>
|
59
59
|
<td>0</td>
|
60
|
-
<td>
|
60
|
+
<td>22.3</td>
|
61
61
|
</tr>
|
62
62
|
|
63
63
|
</tbody>
|
@@ -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="123" data-linenumber="15">
|
178
|
+
<span class="hits">123</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="
|
190
|
-
<span class="hits">
|
189
|
+
<li class="covered" data-hits="123" data-linenumber="17">
|
190
|
+
<span class="hits">123</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="
|
202
|
-
<span class="hits">
|
201
|
+
<li class="covered" data-hits="92" data-linenumber="19">
|
202
|
+
<span class="hits">92</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="92" data-linenumber="20">
|
208
|
+
<span class="hits">92</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="87" data-linenumber="21">
|
214
|
+
<span class="hits">87</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="87" data-linenumber="22">
|
220
|
+
<span class="hits">87</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="
|
226
|
-
<span class="hits">
|
225
|
+
<li class="covered" data-hits="87" data-linenumber="23">
|
226
|
+
<span class="hits">87</span>
|
227
227
|
|
228
228
|
<code class="ruby"> validate!(params[name], options)</code>
|
229
229
|
</li>
|
@@ -324,14 +324,14 @@
|
|
324
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="17" data-linenumber="40">
|
328
|
+
<span class="hits">17</span>
|
329
329
|
|
330
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="17" data-linenumber="41">
|
334
|
+
<span class="hits">17</span>
|
335
335
|
|
336
336
|
<code class="ruby"> names = args.collect(&:to_s)</code>
|
337
337
|
</li>
|
@@ -342,10 +342,10 @@
|
|
342
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="17" data-linenumber="43">
|
346
|
+
<span class="hits">17</span>
|
347
347
|
|
348
|
-
<code class="ruby"> return unless names.length >
|
348
|
+
<code class="ruby"> return unless names.length >= 2</code>
|
349
349
|
</li>
|
350
350
|
|
351
351
|
<li class="never" data-hits="" data-linenumber="44">
|
@@ -354,26 +354,26 @@
|
|
354
354
|
<code class="ruby"></code>
|
355
355
|
</li>
|
356
356
|
|
357
|
-
<li class="covered" data-hits="
|
358
|
-
<span class="hits">
|
357
|
+
<li class="covered" data-hits="13" data-linenumber="45">
|
358
|
+
<span class="hits">13</span>
|
359
359
|
|
360
360
|
<code class="ruby"> begin</code>
|
361
361
|
</li>
|
362
362
|
|
363
|
-
<li class="covered" data-hits="
|
364
|
-
<span class="hits">
|
363
|
+
<li class="covered" data-hits="13" data-linenumber="46">
|
364
|
+
<span class="hits">13</span>
|
365
365
|
|
366
366
|
<code class="ruby"> validate_one_of!(params, names, options)</code>
|
367
367
|
</li>
|
368
368
|
|
369
|
-
<li class="covered" data-hits="
|
370
|
-
<span class="hits">
|
369
|
+
<li class="covered" data-hits="5" data-linenumber="47">
|
370
|
+
<span class="hits">5</span>
|
371
371
|
|
372
372
|
<code class="ruby"> rescue InvalidParameterError => exception</code>
|
373
373
|
</li>
|
374
374
|
|
375
|
-
<li class="covered" data-hits="
|
376
|
-
<span class="hits">
|
375
|
+
<li class="covered" data-hits="5" data-linenumber="48">
|
376
|
+
<span class="hits">5</span>
|
377
377
|
|
378
378
|
<code class="ruby"> if options[:raise] or (settings.raise_sinatra_param_exceptions rescue false)</code>
|
379
379
|
</li>
|
@@ -402,20 +402,20 @@
|
|
402
402
|
<code class="ruby"></code>
|
403
403
|
</li>
|
404
404
|
|
405
|
-
<li class="covered" data-hits="
|
406
|
-
<span class="hits">
|
405
|
+
<li class="covered" data-hits="4" data-linenumber="53">
|
406
|
+
<span class="hits">4</span>
|
407
407
|
|
408
408
|
<code class="ruby"> error = "Parameters #{names.join(', ')} are mutually exclusive"</code>
|
409
409
|
</li>
|
410
410
|
|
411
|
-
<li class="covered" data-hits="
|
412
|
-
<span class="hits">
|
411
|
+
<li class="covered" data-hits="4" data-linenumber="54">
|
412
|
+
<span class="hits">4</span>
|
413
413
|
|
414
414
|
<code class="ruby"> if content_type and content_type.match(mime_type(:json))</code>
|
415
415
|
</li>
|
416
416
|
|
417
|
-
<li class="covered" data-hits="
|
418
|
-
<span class="hits">
|
417
|
+
<li class="covered" data-hits="4" data-linenumber="55">
|
418
|
+
<span class="hits">4</span>
|
419
419
|
|
420
420
|
<code class="ruby"> error = {message: error, errors: {names => exception.message}}.to_json</code>
|
421
421
|
</li>
|
@@ -432,8 +432,8 @@
|
|
432
432
|
<code class="ruby"></code>
|
433
433
|
</li>
|
434
434
|
|
435
|
-
<li class="covered" data-hits="
|
436
|
-
<span class="hits">
|
435
|
+
<li class="covered" data-hits="4" data-linenumber="58">
|
436
|
+
<span class="hits">4</span>
|
437
437
|
|
438
438
|
<code class="ruby"> halt 400, error</code>
|
439
439
|
</li>
|
@@ -474,20 +474,20 @@
|
|
474
474
|
<code class="ruby"> def coerce(param, type, options = {})</code>
|
475
475
|
</li>
|
476
476
|
|
477
|
-
<li class="covered" data-hits="
|
478
|
-
<span class="hits">
|
477
|
+
<li class="covered" data-hits="92" data-linenumber="65">
|
478
|
+
<span class="hits">92</span>
|
479
479
|
|
480
480
|
<code class="ruby"> begin</code>
|
481
481
|
</li>
|
482
482
|
|
483
|
-
<li class="covered" data-hits="
|
484
|
-
<span class="hits">
|
483
|
+
<li class="covered" data-hits="92" data-linenumber="66">
|
484
|
+
<span class="hits">92</span>
|
485
485
|
|
486
486
|
<code class="ruby"> return nil if param.nil?</code>
|
487
487
|
</li>
|
488
488
|
|
489
|
-
<li class="covered" data-hits="
|
490
|
-
<span class="hits">
|
489
|
+
<li class="covered" data-hits="85" data-linenumber="67">
|
490
|
+
<span class="hits">85</span>
|
491
491
|
|
492
492
|
<code class="ruby"> return param if (param.is_a?(type) rescue false)</code>
|
493
493
|
</li>
|
@@ -588,8 +588,8 @@
|
|
588
588
|
<code class="ruby"> def validate!(param, options)</code>
|
589
589
|
</li>
|
590
590
|
|
591
|
-
<li class="covered" data-hits="
|
592
|
-
<span class="hits">
|
591
|
+
<li class="covered" data-hits="87" data-linenumber="84">
|
592
|
+
<span class="hits">87</span>
|
593
593
|
|
594
594
|
<code class="ruby"> options.each do |key, value|</code>
|
595
595
|
</li>
|
@@ -816,8 +816,8 @@
|
|
816
816
|
<code class="ruby"> def validate_one_of!(params, names, options)</code>
|
817
817
|
</li>
|
818
818
|
|
819
|
-
<li class="covered" data-hits="
|
820
|
-
<span class="hits">
|
819
|
+
<li class="covered" data-hits="47" data-linenumber="122">
|
820
|
+
<span class="hits">47</span>
|
821
821
|
|
822
822
|
<code class="ruby"> raise InvalidParameterError, "Parameters #{names.join(', ')} are mutually exclusive" if names.count{|name| present?(params[name])} > 1</code>
|
823
823
|
</li>
|
@@ -846,8 +846,8 @@
|
|
846
846
|
<code class="ruby"> def present?(object)</code>
|
847
847
|
</li>
|
848
848
|
|
849
|
-
<li class="covered" data-hits="
|
850
|
-
<span class="hits">
|
849
|
+
<li class="covered" data-hits="34" data-linenumber="127">
|
850
|
+
<span class="hits">34</span>
|
851
851
|
|
852
852
|
<code class="ruby"> !blank?(object)</code>
|
853
853
|
</li>
|
@@ -870,8 +870,8 @@
|
|
870
870
|
<code class="ruby"> def blank?(object)</code>
|
871
871
|
</li>
|
872
872
|
|
873
|
-
<li class="covered" data-hits="
|
874
|
-
<span class="hits">
|
873
|
+
<li class="covered" data-hits="34" data-linenumber="131">
|
874
|
+
<span class="hits">34</span>
|
875
875
|
|
876
876
|
<code class="ruby"> object.respond_to?(:empty?) ? object.empty? : !object</code>
|
877
877
|
</li>
|
data/lib/sinatra/param.rb
CHANGED
Binary file
|
data/sinatra-param.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.summary = "Parameter Validation & Type Coercion for Sinatra."
|
13
13
|
s.description = "sinatra-param allows you to declare, validate, and transform endpoint parameters as you would in frameworks like ActiveModel or DataMapper."
|
14
14
|
|
15
|
-
s.add_dependency "sinatra",
|
15
|
+
s.add_dependency "sinatra", "~> 1.3"
|
16
16
|
|
17
17
|
s.add_development_dependency "rake"
|
18
18
|
s.add_development_dependency "rspec"
|
data/spec/dummy/app.rb
CHANGED
@@ -185,7 +185,31 @@ class App < Sinatra::Base
|
|
185
185
|
params.to_json
|
186
186
|
end
|
187
187
|
|
188
|
-
get '/choice' do
|
188
|
+
get '/choice/1' do
|
189
|
+
param :a, String
|
190
|
+
param :b, String
|
191
|
+
param :c, String
|
192
|
+
|
193
|
+
one_of :a
|
194
|
+
|
195
|
+
{
|
196
|
+
message: 'OK'
|
197
|
+
}.to_json
|
198
|
+
end
|
199
|
+
|
200
|
+
get '/choice/2' do
|
201
|
+
param :a, String
|
202
|
+
param :b, String
|
203
|
+
param :c, String
|
204
|
+
|
205
|
+
one_of :a, :b
|
206
|
+
|
207
|
+
{
|
208
|
+
message: 'OK'
|
209
|
+
}.to_json
|
210
|
+
end
|
211
|
+
|
212
|
+
get '/choice/3' do
|
189
213
|
param :a, String
|
190
214
|
param :b, String
|
191
215
|
param :c, String
|
@@ -202,7 +226,7 @@ class App < Sinatra::Base
|
|
202
226
|
params.to_json
|
203
227
|
end
|
204
228
|
|
205
|
-
get '/raise/choice' do
|
229
|
+
get '/raise/choice/3' do
|
206
230
|
param :a, String
|
207
231
|
param :b, String
|
208
232
|
param :c, String
|
@@ -10,13 +10,22 @@ describe 'Parameter Sets' do
|
|
10
10
|
]
|
11
11
|
|
12
12
|
params.each do |param|
|
13
|
-
get('/choice', param) do |response|
|
13
|
+
get('/choice/3', param) do |response|
|
14
14
|
expect(response.status).to eql 400
|
15
15
|
expect(JSON.parse(response.body)['message']).to match(/mutually exclusive/)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
it 'returns 400 on requests that contain more than one mutually exclusive parameter' do
|
21
|
+
params = {a: 1, b: 2}
|
22
|
+
|
23
|
+
get('/choice/2', params) do |response|
|
24
|
+
expect(response.status).to eql 400
|
25
|
+
expect(JSON.parse(response.body)['message']).to match(/mutually exclusive/)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
20
29
|
it 'returns successfully for requests that have one parameter' do
|
21
30
|
params = [
|
22
31
|
{a: 1},
|
@@ -24,18 +33,22 @@ describe 'Parameter Sets' do
|
|
24
33
|
{c: 3}
|
25
34
|
]
|
26
35
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
36
|
+
(1..3).each do |n|
|
37
|
+
params.each do |param|
|
38
|
+
get("/choice/#{n}", param) do |response|
|
39
|
+
expect(response.status).to eql 200
|
40
|
+
expect(JSON.parse(response.body)['message']).to match(/OK/)
|
41
|
+
end
|
31
42
|
end
|
32
43
|
end
|
33
44
|
end
|
34
45
|
|
35
46
|
it 'returns successfully for requests that have no parameter' do
|
36
|
-
|
37
|
-
|
38
|
-
|
47
|
+
(1..3).each do |n|
|
48
|
+
get("/choice/#{n}") do |response|
|
49
|
+
expect(response.status).to eql 200
|
50
|
+
expect(JSON.parse(response.body)['message']).to match(/OK/)
|
51
|
+
end
|
39
52
|
end
|
40
53
|
end
|
41
54
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-param
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattt Thompson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -140,6 +140,7 @@ files:
|
|
140
140
|
- ./LICENSE
|
141
141
|
- ./Rakefile
|
142
142
|
- ./README.md
|
143
|
+
- ./sinatra-param-1.3.0.gem
|
143
144
|
- ./sinatra-param.gemspec
|
144
145
|
- spec/dummy/app.rb
|
145
146
|
- spec/parameter_exclusivity_spec.rb
|