Class: UserRegistration::UsingPassword

Inherits:
Base
  • Object
show all
Includes:
Notifications, SubscribeVoucherReward
Defined in:
app/my_lib/user_registration/using_password.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SubscribeVoucherReward

#voucher_reward_subscription

Methods included from Notifications

#send_registration_email, #send_registration_sms

Methods inherited from Base

#method_missing, #save

Constructor Details

#initialize(attrs = {}) ⇒ UsingPassword

Returns a new instance of UsingPassword.



13
14
15
# File 'app/my_lib/user_registration/using_password.rb', line 13

def initialize(attrs = {})
  @user = User.new attrs
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class UserRegistration::Base

Instance Attribute Details

#userObject

Returns the value of attribute user.



11
12
13
# File 'app/my_lib/user_registration/using_password.rb', line 11

def user
  @user
end

Instance Method Details

#full_error_messageObject



34
35
36
# File 'app/my_lib/user_registration/using_password.rb', line 34

def full_error_message
  user.errors&.full_messages&.uniq&.to_sentence
end

#save!Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/my_lib/user_registration/using_password.rb', line 17

def save!
  raise RegistrationError, user.errors.full_messages.to_sentence unless user.valid?

  raise RegistrationError, user.errors.full_messages.to_sentence unless user.save

  ActiveRecord::Base.transaction do
    send_registration_email
    voucher_reward_subscription
  end
  true
rescue ActiveRecord::ActiveRecordError => error
  APMErrorHandler.report(error)
  user.errors.add(:base, 'Sorry, something went wrong')

  false
end