Class: Textus::Protocol::Gate
- Inherits:
-
Object
- Object
- Textus::Protocol::Gate
- Defined in:
- lib/textus/protocol/gate.rb
Constant Summary collapse
- HANDLER_GROUPS =
{ read: Handlers::Read, write: Handlers::Write, maintenance: Handlers::System, }.freeze
Instance Method Summary collapse
- #dispatch(role, verb, params = {}, call: nil) ⇒ Object
-
#initialize(manifest:, resolver:, container:, store_engine:, policy: nil, async: nil) ⇒ Gate
constructor
A new instance of Gate.
Constructor Details
#initialize(manifest:, resolver:, container:, store_engine:, policy: nil, async: nil) ⇒ Gate
Returns a new instance of Gate.
10 11 12 13 14 15 16 17 |
# File 'lib/textus/protocol/gate.rb', line 10 def initialize(manifest:, resolver:, container:, store_engine:, policy: nil, async: nil) @manifest = manifest @resolver = resolver @container = container @store_engine = store_engine @async = async @policy = policy || manifest.policy end |
Instance Method Details
#dispatch(role, verb, params = {}, call: nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/textus/protocol/gate.rb', line 19 def dispatch(role, verb, params = {}, call: nil) spec = VerbRegistry.for(verb) return error(:unknown_verb, "Unknown verb: #{verb}") unless spec key = params[:key] (role, verb, key, spec) call_obj = call || Value::Call.build(role:, correlation_id: SecureRandom.uuid) bound = Protocol::Binder.bind(spec, params) ctx_class = spec.read? && !spec.system? ? Handlers::QueryContext : Handlers::CommandContext ctx = ctx_class.new(@store_engine, @container, call_obj) handler = spec.lane ? Lane.handler_for(spec.lane) : handler_group(spec) handler.public_send(verb, **bound, ctx:, call: call_obj) end |