You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+14Lines changed: 14 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1152,6 +1152,20 @@ params do
1152
1152
end
1153
1153
```
1154
1154
1155
+
Finally, for even greater control, an explicit validation Proc may be supplied using ```proc```.
1156
+
It will be called with a single argument (the input value), and should return
1157
+
a truthy value if the value passes validation. If the input is an array, the Proc will be called
1158
+
multiple times, once for each element in the array.
1159
+
1160
+
```ruby
1161
+
params do
1162
+
requires :number, type:Integer, values: { proc:->(v) { v.even? && v <25 }, message:'is odd or greater than 25' }
1163
+
end
1164
+
```
1165
+
1166
+
While ```proc``` is convenient for single cases, consider using [Custom Validators](#custom-validators) in cases where a validation is used more than once.
1167
+
1168
+
1155
1169
#### `regexp`
1156
1170
1157
1171
Parameters can be restricted to match a specific regular expression with the `:regexp` option. If the value
0 commit comments