Class: UserEmail
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- UserEmail
- Defined in:
- app/models/user_email.rb
Instance Attribute Summary collapse
-
#skip_normalize_email ⇒ Object
Returns the value of attribute skip_normalize_email.
-
#skip_validate_email ⇒ Object
Returns the value of attribute skip_validate_email.
-
#skip_validate_unique_email ⇒ Object
Returns the value of attribute skip_validate_unique_email.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#skip_normalize_email ⇒ Object
Returns the value of attribute skip_normalize_email.
8 9 10 |
# File 'app/models/user_email.rb', line 8 def skip_normalize_email @skip_normalize_email end |
#skip_validate_email ⇒ Object
Returns the value of attribute skip_validate_email.
6 7 8 |
# File 'app/models/user_email.rb', line 6 def skip_validate_email @skip_validate_email end |
#skip_validate_unique_email ⇒ Object
Returns the value of attribute skip_validate_unique_email.
7 8 9 |
# File 'app/models/user_email.rb', line 7 def skip_validate_unique_email @skip_validate_unique_email end |
Class Method Details
.ensure_consistency! ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/user_email.rb', line 25 def self.ensure_consistency! user_ids_without_primary_email = DB.query_single <<~SQL SELECT u.id FROM users u LEFT JOIN user_emails ue ON u.id = ue.user_id AND ue.primary = true WHERE ue.id IS NULL; SQL user_ids_without_primary_email.each do |user_id| UserEmail.create!( user_id: user_id, # 64 max character length of local-part for the email address https://datatracker.ietf.org/doc/html/rfc5321#section-4.5.3.1.1 email: "#{SecureRandom.alphanumeric(64)}@missing-primary-email.invalid", primary: true, ) end end |
Instance Method Details
#normalize_email ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'app/models/user_email.rb', line 43 def normalize_email self.normalized_email = if self.email.present? username, domain = self.email.split("@", 2) username = username.gsub(".", "").gsub(/\+.*/, "") "#{username}@#{domain}" end end |