Class: Spree::LocaleCodesValidator
- Inherits:
-
ActiveModel::Validator
- Object
- ActiveModel::Validator
- Spree::LocaleCodesValidator
- Defined in:
- app/validators/spree/locale_codes_validator.rb
Overview
Rejects locale codes Spree::Locales::ALL does not list, in a single code
or a comma-separated list, naming the ones it refuses. Reads the stored
column, since a store answers default_locale from its default market,
and checks only an attribute that is changing, so a record saved before
the list was enforced can still be edited.
Instance Method Summary collapse
Instance Method Details
#validate(record) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'app/validators/spree/locale_codes_validator.rb', line 11 def validate(record) Array([:attributes]).each do |attribute| next unless record.will_save_change_to_attribute?(attribute) unlisted = Spree::Locales.unlisted(record.read_attribute(attribute)) next if unlisted.empty? record.errors.add(attribute, I18n.t('spree.locales_not_listed', codes: unlisted.join(', '))) end end |