sinatra-param-validator 0.5.0 → 0.6.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 -1
- data/lib/sinatra/param_validator/parser.rb +4 -0
- 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: 2f824395ffa6b3e38d61c1e4cd81ee2237987c47b04c51abb4cd43d2fdedd2ec
|
4
|
+
data.tar.gz: 9294cc7618a05d263df6f7e7415fdab88b0f6e846b05fce4cac2763d8a79b740
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17ed2207a700e74b5114ac4b10fb9f8a3f6089d6661df044017a5b36ea558ffec2452e62d7ec0814a5ce30536ab039569cfa45f031960e791caaf57ae253afac
|
7
|
+
data.tar.gz: 8dd242fdf3f379612962ca5897e23e86782b061b16373bfc3dbf4b6e3e22b95e39787027e1499cca36872c9d88b7246871bbb882f6472caadbd5004de7763be4
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -118,12 +118,20 @@ with a message, and it will be passed through as an error for the parameter.
|
|
118
118
|
If you need to do further validation with your parameter, the validator can be passed to the block:
|
119
119
|
|
120
120
|
```ruby
|
121
|
-
|
122
121
|
param :number, Integer, required: true do |validator|
|
123
122
|
validator.param :digit, Integer, min: params[:number]
|
124
123
|
end
|
125
124
|
```
|
126
125
|
|
126
|
+
If you need to run some code in the route context, you can just use the `block` keyword:
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
block do |validator|
|
130
|
+
#...
|
131
|
+
validator.param :val, Integer
|
132
|
+
end
|
133
|
+
```
|
134
|
+
|
127
135
|
## Rules
|
128
136
|
|
129
137
|
Rules work on multiple parameters:
|
@@ -24,6 +24,10 @@ module Sinatra
|
|
24
24
|
@errors[key] = @errors.fetch(key, []).concat(Array(error))
|
25
25
|
end
|
26
26
|
|
27
|
+
def block(&block)
|
28
|
+
run_block :block, block
|
29
|
+
end
|
30
|
+
|
27
31
|
def param(key, type, message: nil, **args, &block)
|
28
32
|
parameter = Parameter.new(@context.params[key], type, **args)
|
29
33
|
@context.params[key] = parameter.coerced if @context.params.key?(key) && parameter.coerced
|