Class: Emails::CreateService

Inherits:
BaseService show all
Defined in:
app/services/emails/create_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #user

Instance Method Summary collapse

Methods inherited from BaseService

#initialize, #notification_service

Constructor Details

This class inherits a constructor from Emails::BaseService

Instance Method Details

#execute(extra_params = {}) ⇒ Object


5
6
7
8
9
10
11
12
# File 'app/services/emails/create_service.rb', line 5

def execute(extra_params = {})
  skip_confirmation = params.delete(:skip_confirmation)

  user.emails.create(params.merge(extra_params)).tap do |email|
    email&.confirm if skip_confirmation && current_user.admin?
    notification_service.new_email_address_added(user, email.email) if email.persisted? && !email.user_primary_email?
  end
end