Module: Devise::Models::MultiEmailAuthenticatable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/devise/multi_email/models/authenticatable.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- EMAILS_ASSOCIATION =
:emails
Class Method Summary collapse
Instance Method Summary collapse
-
#email ⇒ Object
Gets the primary email address of the user.
-
#email=(email) ⇒ Object
Sets the default email address of the user.
-
#primary_email_record ⇒ Object
Gets the primary email record.
Class Method Details
.required_fields(klass) ⇒ Object
28 29 30 |
# File 'lib/devise/multi_email/models/authenticatable.rb', line 28 def self.required_fields(klass) [] end |
Instance Method Details
#email ⇒ Object
Gets the primary email address of the user.
44 45 46 |
# File 'lib/devise/multi_email/models/authenticatable.rb', line 44 def email primary_email_record.try(:email) end |
#email=(email) ⇒ Object
Sets the default email address of the user.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/devise/multi_email/models/authenticatable.rb', line 49 def email=(email) record = primary_email_record if email record ||= emails.build record.email = email record.primary = true elsif email.nil? && record record.mark_for_destruction end end |
#primary_email_record ⇒ Object
Gets the primary email record.
33 34 35 36 37 38 39 40 41 |
# File 'lib/devise/multi_email/models/authenticatable.rb', line 33 def primary_email_record valid_emails = emails.each.select do |email_record| !email_record.destroyed? && !email_record.marked_for_destruction? end result = valid_emails.find(&:primary?) result ||= valid_emails.first result end |