mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 01:11:43 +02:00
Revert "Registry 569"
This commit is contained in:
parent
9565f23e68
commit
4786dbb943
50 changed files with 323 additions and 2463 deletions
|
@ -1,20 +0,0 @@
|
|||
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
|
|
@ -1,22 +0,0 @@
|
|||
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
|
|
@ -1,21 +0,0 @@
|
|||
class Contact::Ident::RegNoValidator < ActiveModel::EachValidator
|
||||
def self.country_specific_formats
|
||||
{
|
||||
Country.new('EE') => /\A[0-9]{8}\z/,
|
||||
}
|
||||
end
|
||||
|
||||
def validate_each(record, attribute, value)
|
||||
format = format_for(record.country)
|
||||
|
||||
return unless format
|
||||
|
||||
record.errors.add(attribute, :invalid_reg_no, country: record.country) unless value =~ format
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def format_for(country)
|
||||
self.class.country_specific_formats[country]
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue