Class: Textus::RoleScope
- Inherits:
-
Object
- Object
- Textus::RoleScope
- Defined in:
- lib/textus/role_scope.rb
Overview
Thin role-scoped facade over a Container. Closes over a role default and a dry_run flag, then forwards every verb in Dispatcher::VERBS to the corresponding use case.
Replaces the per-call Session under the 0.27.0 architecture: a Store exposes #as(role) to get a RoleScope, and Store#put / Store#get / etc delegate to RoleScope under the default role.
Instance Attribute Summary collapse
-
#container ⇒ Object
readonly
Returns the value of attribute container.
-
#correlation_id ⇒ Object
readonly
Returns the value of attribute correlation_id.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
Instance Method Summary collapse
-
#dispatch_bound(verb, inputs, session: nil) ⇒ Object
Single bind + invoke site for every surface.
- #dry_run? ⇒ Boolean
- #hook_context ⇒ Object
-
#initialize(container:, role:, dry_run: false, correlation_id: nil) ⇒ RoleScope
constructor
A new instance of RoleScope.
- #with_correlation_id(cid) ⇒ Object
- #with_dry_run ⇒ Object
- #with_role(role) ⇒ Object
Constructor Details
#initialize(container:, role:, dry_run: false, correlation_id: nil) ⇒ RoleScope
Returns a new instance of RoleScope.
16 17 18 19 20 21 |
# File 'lib/textus/role_scope.rb', line 16 def initialize(container:, role:, dry_run: false, correlation_id: nil) @container = container @role = role.to_s @dry_run = dry_run @correlation_id = correlation_id end |
Instance Attribute Details
#container ⇒ Object (readonly)
Returns the value of attribute container.
10 11 12 |
# File 'lib/textus/role_scope.rb', line 10 def container @container end |
#correlation_id ⇒ Object (readonly)
Returns the value of attribute correlation_id.
10 11 12 |
# File 'lib/textus/role_scope.rb', line 10 def correlation_id @correlation_id end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
10 11 12 |
# File 'lib/textus/role_scope.rb', line 10 def role @role end |
Instance Method Details
#dispatch_bound(verb, inputs, session: nil) ⇒ Object
Single bind + invoke site for every surface. ‘inputs` is the uniform by-name hash (the binder’s currency). MCP/CLI build it from their raw transport shape and call this directly; the per-verb Ruby methods below normalize positional+keyword Ruby args into ‘inputs` and delegate here.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/textus/role_scope.rb', line 43 def dispatch_bound(verb, inputs, session: nil) klass = Textus::Dispatcher::VERBS[verb] spec = (klass.contract if klass.respond_to?(:contract?) && klass.contract?) invoke = lambda do |effective_inputs| args, kwargs = if spec Textus::Contract::Binder.bind(spec, effective_inputs, session: session) else [[], effective_inputs] end call_value = Textus::Call.build(role: @role, correlation_id: @correlation_id, dry_run: @dry_run) Textus::Dispatcher.invoke(verb, container: @container, call: call_value, args: args, kwargs: kwargs) end if spec&.around Textus::Contract::Around.with(spec.around, scope: self, inputs: inputs, session: session, &invoke) else invoke.call(inputs) end end |
#dry_run? ⇒ Boolean
12 13 14 |
# File 'lib/textus/role_scope.rb', line 12 def dry_run? @dry_run end |
#hook_context ⇒ Object
31 32 33 |
# File 'lib/textus/role_scope.rb', line 31 def hook_context @hook_context ||= Textus::Hooks::Context.new(scope: self) end |
#with_correlation_id(cid) ⇒ Object
27 28 29 |
# File 'lib/textus/role_scope.rb', line 27 def with_correlation_id(cid) self.class.new(container: @container, role: @role, dry_run: @dry_run, correlation_id: cid) end |
#with_dry_run ⇒ Object
35 36 37 |
# File 'lib/textus/role_scope.rb', line 35 def with_dry_run self.class.new(container: @container, role: @role, dry_run: true, correlation_id: @correlation_id) end |
#with_role(role) ⇒ Object
23 24 25 |
# File 'lib/textus/role_scope.rb', line 23 def with_role(role) self.class.new(container: @container, role: role, dry_run: @dry_run, correlation_id: @correlation_id) end |