Module: ActiveModel::Validations::EmptyBlankEachValidator

Included in:
BicValidator, CifValidator, CnpValidator, IbanValidator
Defined in:
lib/romanianvalidators.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/romanianvalidators.rb', line 10

def validate_each(record, attribute, value)
  allow_blank = options.fetch(:allow_blank, false)
  allow_nil = options.fetch(:allow_nil, false)
  message = options.fetch(:message, :invalid)
  record.errors.add_on_empty(attribute) && return if value.nil? && !allow_nil
  record.errors.add_on_blank(attribute) && return if value.blank? && !allow_blank
  record.errors.add(attribute, message) && return unless valid?(value)
end