Revert "Registry 569"

This commit is contained in:
Timo Võhmar 2017-10-05 16:08:47 +03:00 committed by GitHub
parent 9565f23e68
commit 4786dbb943
50 changed files with 323 additions and 2463 deletions

View file

@ -1,12 +0,0 @@
class E164Validator < ActiveModel::EachValidator
def validate_each(record, attribute, _value)
length_validator = ActiveModel::Validations::
LengthValidator.new(maximum: 17, attributes: attribute)
length_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

View file

@ -1,11 +0,0 @@
class Iso31661Alpha2Validator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.errors.add(attribute, :invalid_iso31661_alpha2) unless valid_country_code?(value)
end
private
def valid_country_code?(country_code)
Country.new(country_code)
end
end

View file

@ -1,13 +0,0 @@
class Iso8601Validator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if options[:date_only]
record.errors.add(attribute, :invalid_iso8601_date) unless value =~ date_format
end
end
private
def date_format
/\d{4}-\d{2}-\d{2}/
end
end

View file

@ -2,11 +2,11 @@ class PhoneValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return if record.errors[:phone].any?
phone_parts = value.split('.')
country_code = phone_parts.first
subscriber_no = phone_parts.second
splitted_phone = value.split('.')
country_code = splitted_phone.first
phone_number = splitted_phone.second
if zeros_only?(country_code) || zeros_only?(subscriber_no)
if zeros_only?(country_code) || zeros_only?(phone_number)
record.errors.add(attribute, :invalid)
end
end