mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +02:00
20 lines
485 B
Ruby
20 lines
485 B
Ruby
class Contact::Ident::MismatchValidator < ActiveModel::Validator
|
|
Mismatch = Struct.new(:type, :country)
|
|
|
|
def self.mismatches
|
|
[
|
|
Mismatch.new('birthday', Country.new('EE')),
|
|
]
|
|
end
|
|
|
|
def validate(record)
|
|
record.errors.add(:base, :mismatch, type: record.type, country: record.country) if mismatched?(record)
|
|
end
|
|
|
|
private
|
|
|
|
def mismatched?(record)
|
|
mismatch = Mismatch.new(record.type, record.country)
|
|
self.class.mismatches.include?(mismatch)
|
|
end
|
|
end
|