Class: RailsBase::EmailChange

Inherits:
ServiceBase show all
Defined in:
app/services/rails_base/email_change.rb

Instance Method Summary collapse

Methods inherited from ServiceBase

inherited, #internal_validate, #service_base_logging

Methods included from ServiceLogging

#aletered_message, #class_name, #log, #log_prefix, #logger, #service_id

Instance Method Details

#callObject



7
8
9
10
11
12
13
14
# File 'app/services/rails_base/email_change.rb', line 7

def call
  context.original_email = user.email
  user.update_attribute(:email, email)
  context.new_email = email
  log(level: :info, msg: "Changed #{user.id} email from: #{context.original_email} to #{email}")
rescue StandardError
  context.fail!(message: 'Unable to update email address. Likely that this email is already taken')
end

#validate!Object



16
17
18
19
# File 'app/services/rails_base/email_change.rb', line 16

def validate!
  raise "Expected email to be a String. Received #{email.class}" unless email.is_a? String
  raise "Expected user to be a User. Received #{user.class}" unless user.is_a? User
end