Class: Rubyists::Leopard::NatsRequestReplyCallbacks
- Inherits:
-
Object
- Object
- Rubyists::Leopard::NatsRequestReplyCallbacks
- Defined in:
- lib/leopard/nats_request_reply_callbacks.rb
Overview
Maps Leopard handler outcomes to request/reply response behavior.
Instance Method Summary collapse
-
#callbacks ⇒ Hash{Symbol => #call}
Returns transport callbacks for request/reply endpoints.
-
#initialize(logger:) ⇒ void
constructor
Builds a callback set for request/reply endpoint outcomes.
-
#log_failure(failure) ⇒ void
private
Logs the failure payload returned by a handler.
-
#respond_with_error(wrapper, error) ⇒ void
private
Responds to a request with an exception payload after an unhandled error.
-
#respond_with_failure(wrapper, result) ⇒ void
private
Responds to a failed request with the failure payload.
-
#respond_with_success(wrapper, result) ⇒ void
private
Responds to a successful request with the handler payload.
Constructor Details
#initialize(logger:) ⇒ void
Builds a callback set for request/reply endpoint outcomes.
12 13 14 |
# File 'lib/leopard/nats_request_reply_callbacks.rb', line 12 def initialize(logger:) @logger = logger end |
Instance Method Details
#callbacks ⇒ Hash{Symbol => #call}
Returns transport callbacks for request/reply endpoints.
19 20 21 22 23 24 25 |
# File 'lib/leopard/nats_request_reply_callbacks.rb', line 19 def callbacks { on_success: method(:respond_with_success), on_failure: method(:respond_with_failure), on_error: method(:respond_with_error), } end |
#log_failure(failure) ⇒ void (private)
This method returns an undefined value.
Logs the failure payload returned by a handler.
65 66 67 |
# File 'lib/leopard/nats_request_reply_callbacks.rb', line 65 def log_failure(failure) @logger.error 'Error processing message: ', failure end |
#respond_with_error(wrapper, error) ⇒ void (private)
This method returns an undefined value.
Responds to a request with an exception payload after an unhandled error.
56 57 58 |
# File 'lib/leopard/nats_request_reply_callbacks.rb', line 56 def respond_with_error(wrapper, error) wrapper.respond_with_error(error) end |
#respond_with_failure(wrapper, result) ⇒ void (private)
This method returns an undefined value.
Responds to a failed request with the failure payload.
45 46 47 48 |
# File 'lib/leopard/nats_request_reply_callbacks.rb', line 45 def respond_with_failure(wrapper, result) log_failure(result.failure) wrapper.respond_with_error(result.failure) end |
#respond_with_success(wrapper, result) ⇒ void (private)
This method returns an undefined value.
Responds to a successful request with the handler payload.
35 36 37 |
# File 'lib/leopard/nats_request_reply_callbacks.rb', line 35 def respond_with_success(wrapper, result) wrapper.respond(result.value!) end |