Sha256: 19a0b1038f19ff6da57df84c1aad43e3243e87dc81dc1ef62517075fc22e3c29

Contents?: true

Size: 386 Bytes

Versions: 3

Compression:

Stored size: 386 Bytes

Contents

module SerialTranslator
  class SerialTranslatorPresenceValidator < ActiveModel::Validations::PresenceValidator
    def validate_each(record, attribute, _value)
      translations = record.__send__("#{attribute}_translations") || {}
      return if translations.values.any?(&:present?)
      record.errors.add_on_blank(attribute, options)
    end

    def kind; :presence end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
serial_translator-1.1.0 lib/serial_translator/serial_translator_presence_validator.rb
serial_translator-1.0.2 lib/serial_translator/serial_translator_presence_validator.rb
serial_translator-1.0.1 lib/serial_translator/serial_translator_presence_validator.rb