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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed6bc853522acf081f09e12f5c27bdaba38100c9
4
- data.tar.gz: 319a7c7ef04009d6f709a9faf9209623d831f93f
3
+ metadata.gz: 51bb4d9b8f81421a0d793c498715a28f329f2b03
4
+ data.tar.gz: dcf4efc7ef4741d3911f9d257b5b93290c76c298
5
5
  SHA512:
6
- metadata.gz: 13ba305e660dec0f8173b474a1ae79e19d570fe977594d91878dacdccb003a636d39abe641aa4911c860fad866908af5cada37bad9da0ce8083dbd8ad858ab88
7
- data.tar.gz: 6dc4d1d351e0261bacd12d2dc5873b82b04f105d3c2e25a64d280c6fb932da41c131bb9ccece3c0cd218caddaa4a1329051c292d7d3bbf2b9ae8c9dbcd93d1e9
6
+ metadata.gz: 99308c05d8a95b98e2a6e7d8b535ef9a8f190075e805e0eb9784e6cfd430a5467c68f26185e6f0a08ed15d8ea36f93095a220311655627a6b7c22b8208d3178e
7
+ data.tar.gz: d94dd2f94a98df3c8645f580dce22a3985555465dc06b57427f5be6cc2c2eace4737cae39fe41136b394cee3139b664ab0e2a8985f1ad74ae69b65fee67aef93
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sinatra-param (1.1.2)
4
+ sinatra-param (1.2.0)
5
5
  sinatra (~> 1.3)
6
6
 
7
7
  GEM
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 value === param
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
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Param
3
- VERSION = '1.1.2'
3
+ VERSION = '1.2.0'
4
4
  end
5
5
  end
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.1.2
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 00:00:00.000000000 Z
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