Class: AuctionFunCore::Operations::UserContext::EmailConfirmationOperation
- Inherits:
-
Base
- Object
- Base
- AuctionFunCore::Operations::UserContext::EmailConfirmationOperation
- Defined in:
- lib/auction_fun_core/operations/user_context/email_confirmation_operation.rb
Overview
Operation class for confirm users by token via email.
Class Method Summary collapse
Instance Method Summary collapse
- #call(attributes) ⇒ Object
-
#persist(user_id, time = Time.current) ⇒ ROM::Struct::User
Calls the user repository class to update database fields.
-
#publish_user_confirmation(user_id, time = Time.current) ⇒ Dry::Monads::Result::Success
Triggers the publication of event users.registration.
-
#validate_contract(attrs) ⇒ Dry::Monads::Result::Success, Dry::Monads::Result::Failure
Calls the authentication contract class to perform the validation and authentication of the informed attributes.
Class Method Details
.call(attributes, &block) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/auction_fun_core/operations/user_context/email_confirmation_operation.rb', line 13 def self.call(attributes, &block) operation = new.call(attributes) return operation unless block Dry::Matcher::ResultMatcher.call(operation, &block) end |
Instance Method Details
#call(attributes) ⇒ Object
TODO:
Add custom doc
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/auction_fun_core/operations/user_context/email_confirmation_operation.rb', line 22 def call(attributes) user = yield validate_contract(attributes) user_repository.transaction do |_t| user = yield persist(user.id) yield publish_user_confirmation(user.id, user.confirmed_at) end Success(user) end |
#persist(user_id, time = Time.current) ⇒ ROM::Struct::User
Calls the user repository class to update database fields.
50 51 52 53 54 |
# File 'lib/auction_fun_core/operations/user_context/email_confirmation_operation.rb', line 50 def persist(user_id, time = Time.current) result = {email_confirmation_token: nil, email_confirmed_at: time, confirmed_at: time} Success(user_repository.update(user_id, result)) end |
#publish_user_confirmation(user_id, time = Time.current) ⇒ Dry::Monads::Result::Success
Triggers the publication of event users.registration.
59 60 61 62 63 |
# File 'lib/auction_fun_core/operations/user_context/email_confirmation_operation.rb', line 59 def publish_user_confirmation(user_id, time = Time.current) Success( Application[:event].publish("users.confirmation", {user_id: user_id, time: time}) ) end |
#validate_contract(attrs) ⇒ Dry::Monads::Result::Success, Dry::Monads::Result::Failure
Calls the authentication contract class to perform the validation and authentication of the informed attributes.
38 39 40 41 42 43 44 |
# File 'lib/auction_fun_core/operations/user_context/email_confirmation_operation.rb', line 38 def validate_contract(attrs) contract = email_confirmation_contract.call(attrs) return Failure(contract.errors.to_h) if contract.failure? Success(contract.context[:user]) end |