Sha256: e0eeb9dbecbbf6631f262d1ce7d1309845da280cdb81a43d4a614d9cdec98b83

Contents?: true

Size: 445 Bytes

Versions: 4

Compression:

Stored size: 445 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?)
      if record.send(attribute).blank?
        record.errors.add(attribute, :blank, options)
      end
    end

    def kind
      :presence
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
serial_translator-2.0.2 lib/serial_translator/serial_translator_presence_validator.rb
serial_translator-2.0.1 lib/serial_translator/serial_translator_presence_validator.rb
serial_translator-2.0.0 lib/serial_translator/serial_translator_presence_validator.rb
serial_translator-1.1.3 lib/serial_translator/serial_translator_presence_validator.rb