Class: Users::UpdateCanonicalEmailService
- Inherits:
-
Object
- Object
- Users::UpdateCanonicalEmailService
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/services/users/update_canonical_email_service.rb
Constant Summary collapse
- INCLUDED_DOMAINS_PATTERN =
[/gmail.com/].freeze
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(user:) ⇒ UpdateCanonicalEmailService
constructor
A new instance of UpdateCanonicalEmailService.
Constructor Details
#initialize(user:) ⇒ UpdateCanonicalEmailService
Returns a new instance of UpdateCanonicalEmailService.
9 10 11 12 13 |
# File 'app/services/users/update_canonical_email_service.rb', line 9 def initialize(user:) raise ArgumentError, "Please provide a user" unless user.is_a?(User) @user = user end |
Instance Method Details
#execute ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/services/users/update_canonical_email_service.rb', line 15 def execute return unless user.email return unless user.email.match? Devise.email_regexp canonical_email = canonicalize_email unless canonical_email # the canonical email doesn't exist, probably because the domain doesn't match # destroy any UserCanonicalEmail record associated with this user user.user_canonical_email&.delete # nothing else to do here return end if user.user_canonical_email # update to the new value user.user_canonical_email.canonical_email = canonical_email else user.build_user_canonical_email(canonical_email: canonical_email) end end |