* use instance setting for enabled target geolocations * add validation for enabled geolocations setting * a start on the UI? * backend tweaks for UI * proper crack at autocomplete component * fix region targeting toggle * e2e spec
21 lines
814 B
Ruby
21 lines
814 B
Ruby
class EnabledCountriesHashValidator < ActiveModel::EachValidator
|
|
VALID_HASH_VALUES = %i[with_regions without_regions].freeze
|
|
|
|
def validate_each(record, attribute, value)
|
|
if value.blank? || !value.is_a?(Hash)
|
|
record.errors.add(attribute,
|
|
options[:message] || I18n.t("validators.iso3166_hash_validator.is_blank"))
|
|
return
|
|
end
|
|
|
|
unless value.keys.all? { |key| ISO3166::Country.codes.include? key }
|
|
record.errors.add(attribute,
|
|
options[:message] || I18n.t("validators.iso3166_hash_validator.invalid_key"))
|
|
end
|
|
|
|
return if value.values.all? { |value| VALID_HASH_VALUES.include? value }
|
|
|
|
record.errors.add(attribute,
|
|
options[:message] || I18n.t("validators.iso3166_hash_validator.invalid_value"))
|
|
end
|
|
end
|