Class: Grape::Validations::AllowBlankValidator

Inherits:
Base
  • Object
show all
Defined in:
lib/grape/validations/validators/allow_blank.rb

Instance Attribute Summary

Attributes inherited from Base

#attrs

Instance Method Summary collapse

Methods inherited from Base

convert_to_short_name, #fail_fast?, inherited, #initialize, #message, #options_key?, #validate, #validate!

Constructor Details

This class inherits a constructor from Grape::Validations::Base

Instance Method Details

#validate_param!(attr_name, params) ⇒ Object



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

def validate_param!(attr_name, params)
  return if (options_key?(:value) ? @option[:value] : @option) || !params.is_a?(Hash)

  value = params[attr_name]
  value = value.strip if value.respond_to?(:strip)

  return if value == false || value.present?

  raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: message(:blank))
end