Class: Textus::RoleScope

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#containerObject (readonly)

Returns the value of attribute container.



10
11
12
# File 'lib/textus/role_scope.rb', line 10

def container
  @container
end

#correlation_idObject (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

#roleObject (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

#dry_run?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/textus/role_scope.rb', line 12

def dry_run?
  @dry_run
end

#hook_contextObject



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_runObject



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