Class: Textus::Gate
- Inherits:
-
Object
- Object
- Textus::Gate
- Defined in:
- lib/textus/gate.rb,
lib/textus/gate/auth.rb,
lib/textus/gate/binder.rb
Defined Under Namespace
Modules: Binder Classes: Auth, MissingArgs
Constant Summary collapse
- CASCADE_VERBS =
%i[put propose accept reject key_mv key_delete].freeze
- AUTH_KEYS =
{ key_mv: ->(params) { [params[:old_key], params[:new_key]] }, ingest: ->(params) { Textus::Action::Ingest.dispatch_key(**params) }, }.freeze
Instance Method Summary collapse
- #dispatch(spec:, inputs:, role:, correlation_id: nil, session: nil, surface: nil) ⇒ Object
-
#initialize(container) ⇒ Gate
constructor
A new instance of Gate.
Constructor Details
#initialize(container) ⇒ Gate
Returns a new instance of Gate.
5 6 7 |
# File 'lib/textus/gate.rb', line 5 def initialize(container) @container = container end |
Instance Method Details
#dispatch(spec:, inputs:, role:, correlation_id: nil, session: nil, surface: nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/textus/gate.rb', line 9 def dispatch(spec:, inputs:, role:, correlation_id: nil, session: nil, surface: nil) resolved = Binder.bind(spec, inputs, session: session) cmd = Value::Command.new(verb: spec.verb, params: resolved.freeze, role: role) cmd = normalize_propose_key(cmd) if cmd.verb == :propose action_class = Textus::Action::VERBS.fetch(cmd.verb) do raise Textus::UsageError.new("unknown command verb: #{cmd.verb}") end auth = Gate::Auth.new(@container) auth.check!(cmd) check_dispatch_auth(cmd, resolved, auth) call_obj = build_call(cmd, correlation_id: correlation_id) result = run_action(action_class, resolved, call_obj) cascade(cmd, result, call_obj) if CASCADE_VERBS.include?(cmd.verb) && !call_obj.dry_run return result unless surface spec.view(surface).call(result, resolved) end |