Class: API::Validations::Validators::IntegerNoneAny

Inherits:
Grape::Validations::Base
  • Object
show all
Defined in:
lib/api/validations/validators/integer_none_any.rb

Instance Method Summary collapse

Instance Method Details

#validate_param!(attr_name, params) ⇒ Object

Raises:

  • (Grape::Exceptions::Validation)

7
8
9
10
11
12
13
14
15
# File 'lib/api/validations/validators/integer_none_any.rb', line 7

def validate_param!(attr_name, params)
  value = params[attr_name]

  return if value.is_a?(Integer) ||
      [IssuableFinder::Params::FILTER_NONE, IssuableFinder::Params::FILTER_ANY].include?(value.to_s.downcase)

  raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)],
                                       message: "should be an integer, 'None' or 'Any'"
end