Class: Portage::Ucp::Dispatcher
- Inherits:
-
Object
- Object
- Portage::Ucp::Dispatcher
- Defined in:
- lib/portage/ucp/dispatcher.rb
Overview
Accepts a UCP-shaped request (capability + action + arguments), routes it through the CapabilityRegistry to the backing Adapter method, and wraps the result as MCP's dual content/structuredContent output (see ยง5).
Instance Method Summary collapse
- #call(capability:, action:, arguments: {}) ⇒ Object
-
#initialize(adapter:, registry: CapabilityRegistry.default) ⇒ Dispatcher
constructor
A new instance of Dispatcher.
Constructor Details
#initialize(adapter:, registry: CapabilityRegistry.default) ⇒ Dispatcher
Returns a new instance of Dispatcher.
7 8 9 10 |
# File 'lib/portage/ucp/dispatcher.rb', line 7 def initialize(adapter:, registry: CapabilityRegistry.default) @adapter = adapter @registry = registry end |
Instance Method Details
#call(capability:, action:, arguments: {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/portage/ucp/dispatcher.rb', line 12 def call(capability:, action:, arguments: {}) capability_definition = @registry.find(capability) raise UnknownCapabilityError, capability if capability_definition.nil? raise CapabilityNotAdvertisedError, capability unless capability_definition.advertised_for?(@adapter) method_name = capability_definition.actions[action] raise UnknownActionError, action if method_name.nil? Portage::Ucp::PaymentTokenGuard.validate!(arguments[:payment_token]) if arguments.key?(:payment_token) result = @adapter.public_send(method_name, **arguments) wrap(capability, result) end |