Class: API::Validations::Validators::IntegerOrCustomValue
- Inherits:
-
Grape::Validations::Validators::Base
- Object
- Grape::Validations::Validators::Base
- API::Validations::Validators::IntegerOrCustomValue
- Defined in:
- lib/api/validations/validators/integer_or_custom_value.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(attrs, options, required, scope, **opts) ⇒ IntegerOrCustomValue
constructor
A new instance of IntegerOrCustomValue.
- #validate_param!(attr_name, params) ⇒ Object
Constructor Details
#initialize(attrs, options, required, scope, **opts) ⇒ IntegerOrCustomValue
Returns a new instance of IntegerOrCustomValue.
7 8 9 10 |
# File 'lib/api/validations/validators/integer_or_custom_value.rb', line 7 def initialize(attrs, , required, scope, **opts) @custom_values = extract_custom_values() super end |
Instance Method Details
#validate_param!(attr_name, params) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/api/validations/validators/integer_or_custom_value.rb', line 12 def validate_param!(attr_name, params) value = params[attr_name] return if value.is_a?(Integer) return if @custom_values.map(&:downcase).include?(value.to_s.downcase) = Gitlab::Sentence.to_exclusive_sentence(['an integer'] + @custom_values) raise Grape::Exceptions::Validation.new( params: [@scope.full_name(attr_name)], message: "should be #{}, however got #{value}" ) end |