Class: AccountFindOrCreateService
- Inherits:
-
BaseOperationService
- Object
- BaseOperationService
- AccountFindOrCreateService
- Includes:
- DefaultErrorContainer
- Defined in:
- app/services/account_find_or_create_service.rb
Overview
if given user data is not found on database, then system will create new user record and send email notification, and another notification but if already exist, then this service will return existing user record on database outcome of this service is [User] class
Instance Attribute Summary collapse
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Attributes inherited from BaseOperationService
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(email, user_attributes) ⇒ AccountFindOrCreateService
constructor
A new instance of AccountFindOrCreateService.
Methods included from DefaultErrorContainer
#error, #error_message_simple, #merge_errors
Methods inherited from BaseOperationService
Constructor Details
#initialize(email, user_attributes) ⇒ AccountFindOrCreateService
Returns a new instance of AccountFindOrCreateService.
14 15 16 17 18 19 |
# File 'app/services/account_find_or_create_service.rb', line 14 def initialize(email, user_attributes) @user = User.find_by(email: email) @params = user_attributes.slice(:name, :phone, :password, :line_id).merge(email: email).tap do |attr| attr[:name] = RemoveEmoji::Sanitize.call(attr[:name]) if attr[:name].present? end end |
Instance Attribute Details
#user ⇒ Object (readonly)
Returns the value of attribute user.
11 12 13 |
# File 'app/services/account_find_or_create_service.rb', line 11 def user @user end |
Instance Method Details
#execute ⇒ Object
21 22 23 24 25 26 |
# File 'app/services/account_find_or_create_service.rb', line 21 def execute return create_new_user if user.blank? self.outcome = user status_true true end |