Class: PhonyPlausibleValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/validators/phony_validator.rb

Overview

Uses the Phony.plausible method to validate an attribute. Usage:

validate :phone_number, :phony_plausible => true

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object

Validates a String using Phony.plausible? method.



7
8
9
10
# File 'lib/validators/phony_validator.rb', line 7

def validate_each(record, attribute, value)
  return if value.blank?
  record.errors.add(attribute,  options[:message] || :improbable_phone) if not Phony.plausible?(value, cc: options[:country_code])
end