Module: Devise::Models::Validatable
- Defined in:
- lib/devise/models/validatable.rb
Overview
Validatable creates all needed validations for a user email and password. It’s optional, given you may want to create the validations by yourself. 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
:
* +email_regexp+: the regular expression used to validate e-mails;
* +password_length+: a range expressing password length. Defaults to 6..128.
Since password_length
is applied in a proc within ‘validates_length_of` it can be overridden at runtime.
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
Instance Method Summary collapse
- #email_required? ⇒ Boolean protected
-
#password_required? ⇒ Boolean
protected
Checks whether a password is needed or not.
Class Method Details
.assert_validations_api!(base) ⇒ Object
:nodoc:
43 44 45 46 47 48 49 50 |
# File 'lib/devise/models/validatable.rb', line 43 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 |
.required_fields(klass) ⇒ Object
24 25 26 |
# File 'lib/devise/models/validatable.rb', line 24 def self.required_fields(klass) [] end |
Instance Method Details
#email_required? ⇒ Boolean (protected)
61 62 63 |
# File 'lib/devise/models/validatable.rb', line 61 def email_required? true end |
#password_required? ⇒ Boolean (protected)
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.
57 58 59 |
# File 'lib/devise/models/validatable.rb', line 57 def password_required? !persisted? || !password.nil? || !password_confirmation.nil? end |