Class: PhonyPlausibleValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- PhonyPlausibleValidator
- Defined in:
- lib/validators/phony_validator.rb
Instance Method Summary collapse
-
#validate_each(record, attribute, value) ⇒ Object
Validates a String using Phony.plausible? method.
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
Validates a String using Phony.plausible? method.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/validators/phony_validator.rb', line 10 def validate_each(record, attribute, value) return if value.blank? @record = record value = PhonyRails.normalize_number(value.dup, default_country_code: normalized_country_code) if normalized_country_code value = PhonyRails.extract_extension(value).first @record.errors.add(attribute, ) unless Phony.plausible?(value, cc: country_number) @record.public_send("#{attribute}=", @record.public_send("#{attribute}_original")) if @record.respond_to?("#{attribute}_original") && !Phony.plausible?(value, cc: country_number) end |