Class: Grape::Validations::Validators::AllowBlankValidator

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

Instance Attribute Summary

Attributes inherited from Base

#attrs

Instance Method Summary collapse

Methods inherited from Base

default_message_key, #fail_fast?, inherited, new, #validate, #validate!

Constructor Details

#initialize(attrs, options, required, scope, opts) ⇒ AllowBlankValidator

Returns a new instance of AllowBlankValidator.



9
10
11
12
# File 'lib/grape/validations/validators/allow_blank_validator.rb', line 9

def initialize(attrs, options, required, scope, opts)
  super
  @value = option_value
end

Instance Method Details

#validate_param!(attr_name, params) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/grape/validations/validators/allow_blank_validator.rb', line 14

def validate_param!(attr_name, params)
  return if @value || !hash_like?(params)

  value = scrub(params[attr_name])
  return if value == false || value.present?

  validation_error!(attr_name)
end