sinatra-param-validator 0.4.0 → 0.5.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +9 -3
- data/lib/sinatra/param_validator/parameter/common.rb +7 -3
- data/lib/sinatra/param_validator/parser.rb +2 -1
- data/lib/sinatra/param_validator/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1312fa49d8b256875f1c6de21269a7be31ab1c3f2ca0a5efdb9902c31b5406d4
|
4
|
+
data.tar.gz: 4b483ce648a24026e26964b0cdd358a4f1256ffe7dc810770e8dbf2b98204306
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2714270e73581d5beb88eb136516fc1d5275d05ebe2a3c5efca08d54b64bb2bcda467cb45cb4ab3fa7fee063606171356f9fe869cbedc0950afc7b92cb5dc8eb
|
7
|
+
data.tar.gz: 692691bde5e786c23897080967004fc5fb5b695d49942fd671db69ef6ec91c00771a0afbfc5e69954b5e22f8e585829c8e08a04b6a954cf14ec46b1c19dfdf8c
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -115,6 +115,15 @@ end
|
|
115
115
|
If you wish to indicate a validation failure within a block, raise `Sinatra::ParameterValidator::InvalidParameterError`
|
116
116
|
with a message, and it will be passed through as an error for the parameter.
|
117
117
|
|
118
|
+
If you need to do further validation with your parameter, the validator can be passed to the block:
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
|
122
|
+
param :number, Integer, required: true do |validator|
|
123
|
+
validator.param :digit, Integer, min: params[:number]
|
124
|
+
end
|
125
|
+
```
|
126
|
+
|
118
127
|
## Rules
|
119
128
|
|
120
129
|
Rules work on multiple parameters:
|
@@ -149,7 +158,6 @@ post '/new-user', validate_form: :new_user do
|
|
149
158
|
# ...
|
150
159
|
end
|
151
160
|
|
152
|
-
|
153
161
|
get '/user/:id', validate_url_param: :user_id do
|
154
162
|
# ...
|
155
163
|
end
|
@@ -170,8 +178,6 @@ post '/number', validate: vi(:new_user, 10) do
|
|
170
178
|
end
|
171
179
|
```
|
172
180
|
|
173
|
-
|
174
|
-
|
175
181
|
## Development
|
176
182
|
|
177
183
|
After checking out the repo, run `bundle install` to install dependencies. Then, run `rake spec` to run the tests.
|
@@ -9,13 +9,17 @@ module Sinatra
|
|
9
9
|
|
10
10
|
def initialize(value, **options)
|
11
11
|
@errors = []
|
12
|
-
@coerced = coerce value
|
13
12
|
@options = options
|
14
13
|
|
14
|
+
begin
|
15
|
+
@coerced = coerce value
|
16
|
+
rescue ArgumentError
|
17
|
+
@errors.push "'#{value}' is not a valid #{self.class}"
|
18
|
+
return
|
19
|
+
end
|
20
|
+
|
15
21
|
validate_options
|
16
22
|
validate unless nil_and_ok?
|
17
|
-
rescue ArgumentError
|
18
|
-
@errors.push "'#{value}' is not a valid #{self.class}"
|
19
23
|
end
|
20
24
|
|
21
25
|
def valid?
|