Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Dakad committed Jul 27, 2024
1 parent 353a42b commit 6bcd4d8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1714,10 +1714,11 @@ end

Parameters with types that support `#length` method can be restricted to have a specific length with the `:length` option.

The validator accepts `:min` or `:max` or both options to validate that the value of the parameter is within the given limits.
The validator accepts `:min` or `:max` or both options or only `:exact` to validate that the value of the parameter is within the given limits.

```ruby
params do
requires :code, type: String, length: { exact: 2 }
requires :str, type: String, length: { min: 3 }
requires :list, type: [Integer], length: { min: 3, max: 5 }
requires :hash, type: Hash, length: { max: 5 }
Expand Down Expand Up @@ -2045,6 +2046,7 @@ end

```ruby
params do
requires :code, type: String, length: { exact: 2, message: 'code is expected to be exactly 2 characters long' }
requires :str, type: String, length: { min: 5, message: 'str is expected to be atleast 5 characters long' }
requires :list, type: [Integer], length: { min: 2, max: 3, message: 'list is expected to have between 2 and 3 elements' }
end
Expand Down

0 comments on commit 6bcd4d8

Please sign in to comment.