Class: AuctionFunCore::Operations::StaffContext::AuthenticationOperation
- Inherits:
-
Base
- Object
- Base
- AuctionFunCore::Operations::StaffContext::AuthenticationOperation
- Defined in:
- lib/auction_fun_core/operations/staff_context/authentication_operation.rb
Overview
Operation class for authenticate staff members.
Class Method Summary collapse
Instance Method Summary collapse
- #call(attributes) {|publish_staff_authentication(staff.id)| ... } ⇒ Object
-
#publish_staff_authentication(staff_id, time = Time.current) ⇒ Dry::Monads::Result::Success
Triggers the publication of event staffs.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
12 13 14 15 16 17 18 |
# File 'lib/auction_fun_core/operations/staff_context/authentication_operation.rb', line 12 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) {|publish_staff_authentication(staff.id)| ... } ⇒ Object
TODO:
Add custom doc
21 22 23 24 25 26 27 |
# File 'lib/auction_fun_core/operations/staff_context/authentication_operation.rb', line 21 def call(attributes) staff = yield validate_contract(attributes) yield publish_staff_authentication(staff.id) Success(staff) end |
#publish_staff_authentication(staff_id, time = Time.current) ⇒ Dry::Monads::Result::Success
Triggers the publication of event staffs.registration.
44 45 46 47 48 |
# File 'lib/auction_fun_core/operations/staff_context/authentication_operation.rb', line 44 def publish_staff_authentication(staff_id, time = Time.current) Success( Application[:event].publish("staffs.authentication", {staff_id: staff_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.
33 34 35 36 37 38 39 |
# File 'lib/auction_fun_core/operations/staff_context/authentication_operation.rb', line 33 def validate_contract(attrs) contract = authentication_contract.call(attrs) return Failure(contract.errors.to_h) if contract.failure? Success(contract.context[:staff]) end |