Class: GlobalPhoneValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/global_phone/validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/global_phone/validator.rb', line 4

def validate_each(record, attribute, value)
  args = [value]
  if (using = options[:using]) && (country_code = record.send(using))
    args << country_code
  end
  unless GlobalPhone.validate(*args)
    record.errors.add attribute, :invalid_phone_number, country_code: country_code
  end
end