sinatra-params-validator 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -18,7 +18,12 @@ with some middleware.
18
18
 
19
19
  ### Examples
20
20
 
21
+ ```
22
+ $ gem install sinatra-params-validator
23
+ ```
24
+
21
25
  ```ruby
26
+ require 'rack/validator/sinatra'
22
27
  require 'sinatra'
23
28
 
24
29
  class App < Sinatra::Base
@@ -60,7 +65,8 @@ class App < Sinatra::Base
60
65
  end
61
66
 
62
67
  validation_required :POST, '/group', :params => [
63
- { :name => :name, :required => true }
68
+ { :name => :name, :required => true },
69
+ { :name => :private, :type => :boolean, :required => true }
64
70
  ]
65
71
 
66
72
  post '/group' do
@@ -111,6 +117,7 @@ Available methods:
111
117
  * is_in_range
112
118
  * is_less_equal_than
113
119
  * is_email
120
+ * is_boolean
114
121
  * matches
115
122
 
116
123
  To see more examples check tests/params_validator_spec.rb
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -32,7 +32,7 @@ module Rack
32
32
  if lazy_check_disabled
33
33
  keys.each { |k|
34
34
  k = k.to_s
35
- unless @params.has_key?(k)
35
+ unless @params.has_key?(k) && !@params[k].empty?
36
36
  @invalid_params.push(k)
37
37
  @missing_params.push(k)
38
38
  @messages.push("#{k} is required")
@@ -127,6 +127,16 @@ module Rack
127
127
  end
128
128
  end
129
129
 
130
+ def is_boolean(key)
131
+ if lazy_check_disabled
132
+ key = key.to_s
133
+ unless @params[key] == 'true' || @params[key] == 'false'
134
+ @invalid_params.push(key)
135
+ @messages.push("#{key} is not a boolean")
136
+ end
137
+ end
138
+ end
139
+
130
140
  def matches(regexp, key)
131
141
  if lazy_check_disabled
132
142
  key = key.to_s
@@ -174,6 +184,7 @@ module Rack
174
184
  float_params = [ ]
175
185
  email_params = [ ]
176
186
  range_params = [ ]
187
+ boolean_params = [ ]
177
188
  matches_params = [ ]
178
189
  default_params = [ ]
179
190
 
@@ -183,11 +194,13 @@ module Rack
183
194
  float_params << (param) if param[:type] == :float
184
195
  email_params << (param) if param[:type] == :email
185
196
  range_params << (param) if param[:range]
197
+ boolean_params << (param) if param[:type] == :boolean
186
198
  matches_params << (param) if param[:matches]
187
199
  default_params << (param) if param[:default]
188
200
  end
189
201
 
190
202
  validator.required required_params
203
+
191
204
  integer_params.each do |param|
192
205
  validator.is_integer param[:name] unless params[param[:name].to_s].nil?
193
206
  end
@@ -200,6 +213,9 @@ module Rack
200
213
  range_params.each do |param|
201
214
  validator.is_in_range param[:range].first, param[:range].last, param[:name] unless params[param[:name].to_s].nil?
202
215
  end
216
+ boolean_params.each do |param|
217
+ validator.is_boolean param[:name] unless params[param[:name].to_s].nil?
218
+ end
203
219
  matches_params.each do |param|
204
220
  validator.matches param[:matches], param[:name] unless params[param[:name].to_s].nil?
205
221
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-params-validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: