Class: PhoneValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- PhoneValidator
- Defined in:
- lib/phone_validator.rb
Overview
Defined at the top level (not under PicoPhone::Rails) so ActiveModel's
validator lookup resolves validates :phone, phone: { ... } to this class —
EachValidator constantizes "#keykey.to_skey.to_s.camelizeValidator" against the
including model's namespace up through Object, same convention the
email_validator gem uses.
validates :phone, phone: { region: "US", allow_blank: true }
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/phone_validator.rb', line 11 def validate_each(record, attribute, value) return if [:allow_blank] && value.blank? return if phone_valid?(value.to_s) record.errors.add(attribute, :invalid_phone, **.slice(:message)) end |