Class: SerialTranslator::SerialTranslatorPresenceValidator

Inherits:
ActiveModel::Validations::PresenceValidator
  • Object
show all
Defined in:
lib/serial_translator/serial_translator_presence_validator.rb

Instance Method Summary collapse

Instance Method Details

#kindObject



11
12
13
# File 'lib/serial_translator/serial_translator_presence_validator.rb', line 11

def kind
  :presence
end

#validate_each(record, attribute, _value) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/serial_translator/serial_translator_presence_validator.rb', line 3

def validate_each(record, attribute, _value)
  translations = record.__send__("#{attribute}_translations") || {}
  return if translations.values.any?(&:present?)
  if record.send(attribute).blank?
    record.errors.add(attribute, :blank, **options)
  end
end