Class: Num2words::Rails::Validators::LocaleValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/num2words/rails/validators/locale_validator.rb

Direct Known Subclasses

Num2wordsLocaleValidator

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/num2words/rails/validators/locale_validator.rb', line 9

def validate_each(record, attribute, value)
  locale = value.to_s.to_sym

  return if Num2words.available_locales.include?(locale)

  record.errors.add(attribute, :unsupported_locale, unsupported_locale: locale)
end