Class: Armot::ActiveRecordExtensions::Validations::PresenceValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
lib/armot/active_record_extensions.rb

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/armot/active_record_extensions.rb', line 189

def validate(record)
  attr_name = options[:attr]
  locales = options[:locales]
  locales = [locales] if [ String, Symbol ].include?(locales.class)

  valid = locales.map do |locale|
    I18n.locale = locale.to_sym
    record.send("#{attr_name}_raw").present?
  end.inject(:&)

  record.errors.add(attr_name, "has to be present for locales #{locales.to_sentence}") unless valid
end