module RomanianValidators::ActiveModel::Validations::EmptyBlankEachValidator

Public Instance Methods

validate_each(record, attribute, value) click to toggle source
# File lib/romanianvalidators/active_model.rb, line 7
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