module Devise::Models::SmsValidatable
Validatable creates all needed validations for a user phone and password. It's optional, given you may want to create the validations by yourself. Automatically validate if the phone is present, unique and its format is valid. Also tests presence of password, confirmation and length.
Options¶ ↑
Validatable adds the following options to devise_for:
* +email_regexp+: the regular expression used to validate e164 format;
Constants
- VALIDATIONS
All validations used by this module.
Public Class Methods
included(base)
click to toggle source
# File lib/devise_sms_confirmable/models/sms_validatable.rb, line 26 def self.included(base) base.extend ClassMethods assert_validations_api!(base) base.class_eval do validates_presence_of :phone, if: :phone_required? validates_uniqueness_of :phone, allow_blank: true, if: :will_save_change_to_phone? validates_format_of :phone, with: e164_phone_regexp, allow_blank: true, if: :will_save_change_to_phone? end end
required_fields(klass)
click to toggle source
# File lib/devise_sms_confirmable/models/sms_validatable.rb, line 22 def self.required_fields(klass) [] end
Protected Instance Methods
phone_required?()
click to toggle source
Checks whether a password is needed or not. For validations only. Passwords are always required if it's a new record, or if the password or confirmation are being set somewhere.
# File lib/devise_sms_confirmable/models/sms_validatable.rb, line 51 def phone_required? true end