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.



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

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.



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

def user
  @user
end

Instance Method Details

#full_error_messageObject



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

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

#save!Object



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

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 => e
  APMErrorHandler.report(e)
  user.errors.add(:base, 'Sorry, something went wrong')

  false
end