module Devise::Models::DecidimValidatable
Validatable creates all needed validations for a user email and password. Automatically validate if the email 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 e-mails; * +password_length+: a range expressing password length. Defaults to 8..72.
Constants
- VALIDATIONS
All validations used by this module.
Public Class Methods
included(base)
click to toggle source
# File lib/devise/models/decidim_validatable.rb, line 25 def self.included(base) base.extend ClassMethods assert_validations_api!(base) base.class_eval do validates_presence_of :email, if: :email_required? validates_uniqueness_of :email, allow_blank: true, if: :email_changed?, scope: :organization validates_format_of :email, with: email_regexp, allow_blank: true, if: :email_changed? validates_presence_of :password, if: :password_required? validates_confirmation_of :password, if: :password_required? validates_length_of :password, within: password_length, allow_blank: true end end
required_fields(_klass)
click to toggle source
# File lib/devise/models/decidim_validatable.rb, line 21 def self.required_fields(_klass) [] end
Protected Instance Methods
email_required?()
click to toggle source
# File lib/devise/models/decidim_validatable.rb, line 58 def email_required? true end
password_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/models/decidim_validatable.rb, line 54 def password_required? !persisted? || !password.nil? || !password_confirmation.nil? end