internetee-registry/app/validators/contact/ident/mismatch_validator.rb
Artur Beljajev d520b5b157 Revert "Revert "Registry 569""
This reverts commit 4786dbb
2017-10-22 23:57:11 +03:00

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