mirror of
https://github.com/internetee/registry.git
synced 2025-07-24 11:38:30 +02:00
22 lines
565 B
Ruby
22 lines
565 B
Ruby
class Contact::Ident::NationalIdValidator < ActiveModel::EachValidator
|
|
def self.country_specific_validations
|
|
{
|
|
Country.new('EE') => proc { |code| Isikukood.new(code).valid? },
|
|
}
|
|
end
|
|
|
|
def validate_each(record, attribute, value)
|
|
validation = validation_for(record.country)
|
|
|
|
return unless validation
|
|
|
|
valid = validation.call(value)
|
|
record.errors.add(attribute, :invalid_national_id, country: record.country) unless valid
|
|
end
|
|
|
|
private
|
|
|
|
def validation_for(country)
|
|
self.class.country_specific_validations[country]
|
|
end
|
|
end
|