sinatra-param 1.1.2 → 1.2.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 +2 -0
- data/lib/sinatra/param.rb +4 -1
- data/lib/sinatra/param/version.rb +1 -1
- data/sinatra-param-1.1.2.gem +0 -0
- data/spec/dummy/app.rb +10 -0
- data/spec/parameter_validations_spec.rb +20 -0
- 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: 51bb4d9b8f81421a0d793c498715a28f329f2b03
|
4
|
+
data.tar.gz: dcf4efc7ef4741d3911f9d257b5b93290c76c298
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99308c05d8a95b98e2a6e7d8b535ef9a8f190075e805e0eb9784e6cfd430a5467c68f26185e6f0a08ed15d8ea36f93095a220311655627a6b7c22b8208d3178e
|
7
|
+
data.tar.gz: d94dd2f94a98df3c8645f580dce22a3985555465dc06b57427f5be6cc2c2eace4737cae39fe41136b394cee3139b664ab0e2a8985f1ad74ae69b65fee67aef93
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -33,6 +33,7 @@ class App < Sinatra::Base
|
|
33
33
|
param :categories, Array
|
34
34
|
param :sort, String, default: "title"
|
35
35
|
param :order, String, in: ["ASC", "DESC"], transform: :upcase, default: "ASC"
|
36
|
+
param :price, String, format: "[<\=>]\s*\$\d+"
|
36
37
|
|
37
38
|
{...}.to_json
|
38
39
|
end
|
@@ -59,6 +60,7 @@ Encapsulate business logic in a consistent way with validations. If a parameter
|
|
59
60
|
- `is`
|
60
61
|
- `in`, `within`, `range`
|
61
62
|
- `min` / `max`
|
63
|
+
- `format`
|
62
64
|
|
63
65
|
### Defaults and Transformations
|
64
66
|
|
data/lib/sinatra/param.rb
CHANGED
@@ -88,8 +88,11 @@ module Sinatra
|
|
88
88
|
else
|
89
89
|
param.nil?
|
90
90
|
end
|
91
|
+
when :format
|
92
|
+
raise InvalidParameterError, "Parameter must be a string if using the format validation" unless param.kind_of?(String)
|
93
|
+
raise InvalidParameterError, "Parameter must match format #{value}" unless param =~ value
|
91
94
|
when :is
|
92
|
-
raise InvalidParameterError, "Parameter must be #{value}" unless
|
95
|
+
raise InvalidParameterError, "Parameter must be #{value}" unless param === value
|
93
96
|
when :in, :within, :range
|
94
97
|
raise InvalidParameterError, "Parameter must be within #{value}" unless param.nil? || case value
|
95
98
|
when Range
|
Binary file
|
data/spec/dummy/app.rb
CHANGED
@@ -121,6 +121,16 @@ class App < Sinatra::Base
|
|
121
121
|
param :arg, String, blank: true
|
122
122
|
end
|
123
123
|
|
124
|
+
get '/validation/format/9000' do
|
125
|
+
param :arg, Integer, format: /9000/
|
126
|
+
params.to_json
|
127
|
+
end
|
128
|
+
|
129
|
+
get '/validation/format/hello' do
|
130
|
+
param :arg, String, format: /hello/
|
131
|
+
params.to_json
|
132
|
+
end
|
133
|
+
|
124
134
|
get '/validation/is' do
|
125
135
|
param :arg, String, is: 'foo'
|
126
136
|
params.to_json
|
@@ -52,6 +52,26 @@ describe 'Parameter Validations' do
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
+
describe 'format' do
|
56
|
+
it 'returns 200 on requests when value matches the param regex' do
|
57
|
+
get('/validation/format/hello', arg: 'hello world') do |response|
|
58
|
+
response.status.should eq(200)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'returns 400 on requests when value does not match the param regex' do
|
63
|
+
get('/validation/format/hello', arg: 'world') do |response|
|
64
|
+
response.status.should eq(400)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'returns 400 on requests when value is not a string' do
|
69
|
+
get('/validation/format/9000', arg: 9000) do |response|
|
70
|
+
response.status.should eq(400)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
55
75
|
describe 'is' do
|
56
76
|
it 'returns 400 on requests when value is other than defined' do
|
57
77
|
get('/validation/is', arg: 'bar') do |response|
|
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.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattt Thompson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- ./README.md
|
143
143
|
- ./sinatra-param-1.1.0.gem
|
144
144
|
- ./sinatra-param-1.1.1.gem
|
145
|
+
- ./sinatra-param-1.1.2.gem
|
145
146
|
- ./sinatra-param.gemspec
|
146
147
|
- spec/dummy/app.rb
|
147
148
|
- spec/parameter_sets_spec.rb
|