Module: Devise::Models::SmsValidatable
- Defined in:
- lib/devise_sms_confirmable/models/sms_validatable.rb
Overview
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;
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- VALIDATIONS =
All validations used by this module.
[:validates_presence_of, :validates_uniqueness_of, :validates_format_of, :validates_confirmation_of, :validates_length_of].freeze
Class Method Summary collapse
-
.assert_validations_api!(base) ⇒ Object
:nodoc:.
- .included(base) ⇒ Object
- .required_fields(klass) ⇒ Object
Class Method Details
.assert_validations_api!(base) ⇒ Object
:nodoc:
37 38 39 40 41 42 43 44 |
# File 'lib/devise_sms_confirmable/models/sms_validatable.rb', line 37 def self.assert_validations_api!(base) #:nodoc: unavailable_validations = VALIDATIONS.select { |v| !base.respond_to?(v) } unless unavailable_validations.empty? raise "Could not use :validatable module since #{base} does not respond " << "to the following methods: #{unavailable_validations.to_sentence}." end end |
.included(base) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# 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) ⇒ Object
22 23 24 |
# File 'lib/devise_sms_confirmable/models/sms_validatable.rb', line 22 def self.required_fields(klass) [] end |