mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 01:47:18 +02:00
parent
7530dd7b62
commit
3de5a0b51b
2 changed files with 13 additions and 11 deletions
|
@ -7,7 +7,7 @@ class Contact::Ident
|
|||
|
||||
validates :code, presence: true, code: true
|
||||
validates :code, iso8601: { date_only: true }, if: :birthday?
|
||||
validates :type, presence: true, inclusion: { in: Proc.new { types } }
|
||||
validates :type, presence: true, inclusion: { in: proc { types } }
|
||||
validates :country_code, presence: true, iso31661_alpha2: true
|
||||
validate :mismatched
|
||||
|
||||
|
@ -16,15 +16,15 @@ class Contact::Ident
|
|||
'2003' => [
|
||||
[:code, :blank],
|
||||
[:type, :blank],
|
||||
[:country_code, :blank],
|
||||
[:country_code, :blank]
|
||||
],
|
||||
'2005' => [
|
||||
[:base, :mismatch],
|
||||
[:code, :invalid_national_id],
|
||||
[:code, :invalid_reg_no],
|
||||
[:code, :invalid_iso8601],
|
||||
[:country_code, :invalid_iso31661_alpha2],
|
||||
],
|
||||
[:country_code, :invalid_iso31661_alpha2]
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -36,7 +36,7 @@ class Contact::Ident
|
|||
|
||||
def self.mismatches
|
||||
[
|
||||
Mismatch.new('birthday', Country.new('EE')),
|
||||
Mismatch.new('birthday', Country.new('EE'))
|
||||
]
|
||||
end
|
||||
|
||||
|
@ -63,7 +63,7 @@ class Contact::Ident
|
|||
private
|
||||
|
||||
# https://github.com/rails/rails/issues/1513
|
||||
def validation_context=(value); end
|
||||
def validation_context=(_value); end
|
||||
|
||||
def mismatched
|
||||
mismatched = self.class.mismatches.include?(Mismatch.new(type, country))
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
class E164Validator < ActiveModel::EachValidator
|
||||
def validate_each(record, attribute, _value)
|
||||
validator = ActiveModel::Validations::LengthValidator.new(maximum: 17, attributes: attribute)
|
||||
validator.validate(record)
|
||||
length_validator = ActiveModel::Validations::
|
||||
LengthValidator.new(maximum: 17, attributes: attribute)
|
||||
length_validator.validate(record)
|
||||
|
||||
validator = ActiveModel::Validations::FormatValidator.new(with: /\+[0-9]{1,3}\.[0-9]{1,14}?/,
|
||||
attributes: attribute)
|
||||
validator.validate(record)
|
||||
format_validator = ActiveModel::Validations::
|
||||
FormatValidator.new(with: /\+[0-9]{1,3}\.[0-9]{1,14}?/,
|
||||
attributes: attribute)
|
||||
format_validator.validate(record)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue