Skip to content

Commit

Permalink
Merge pull request #2220 from mocaberos/update-readme
Browse files Browse the repository at this point in the history
Update README.md (changes Grape::Validations::Base into Grape::Validations::Validators::Base)
  • Loading branch information
dm1try authored Dec 31, 2021
2 parents 68172c0 + 814d778 commit 29baa9d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,7 @@ end
### Custom Validators

```ruby
class AlphaNumeric < Grape::Validations::Base
class AlphaNumeric < Grape::Validations::Validators::Base
def validate_param!(attr_name, params)
unless params[attr_name] =~ /\A[[:alnum:]]+\z/
fail Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message: 'must consist of alpha-numeric characters'
Expand All @@ -1761,7 +1761,7 @@ end
You can also create custom classes that take parameters.

```ruby
class Length < Grape::Validations::Base
class Length < Grape::Validations::Validators::Base
def validate_param!(attr_name, params)
unless params[attr_name].length <= @option
fail Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message: "must be at the most #{@option} characters long"
Expand All @@ -1779,7 +1779,7 @@ end
You can also create custom validation that use request to validate the attribute. For example if you want to have parameters that are available to only admins, you can do the following.

```ruby
class Admin < Grape::Validations::Base
class Admin < Grape::Validations::Validators::Base
def validate(request)
# return if the param we are checking was not in request
# @attrs is a list containing the attribute we are currently validating
Expand Down

0 comments on commit 29baa9d

Please sign in to comment.