Class: CommandTower::Clients::ScopedClient
- Inherits:
-
Object
- Object
- CommandTower::Clients::ScopedClient
show all
- Defined in:
- app/services/command_tower/clients/scoped_client.rb
Overview
Request-scoped handle around a memoized provider. Holds opaque scope kwargs
(e.g. user:, access_token:) without interpreting provider credentials.
Defined Under Namespace
Classes: NamespaceHandle
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(provider:, **scope) ⇒ ScopedClient
Returns a new instance of ScopedClient.
10
11
12
13
14
15
16
17
|
# File 'app/services/command_tower/clients/scoped_client.rb', line 10
def initialize(provider:, **scope)
raise Errors::ConfigurationError, "provider is required" if provider.nil?
@provider = provider
@scope = scope.freeze
@namespace_mutex = Mutex.new
@namespaces = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, **kwargs, &block) ⇒ Object
39
40
41
42
43
44
45
46
47
48
|
# File 'app/services/command_tower/clients/scoped_client.rb', line 39
def method_missing(name, *args, **kwargs, &block)
return super if block || args.any? || !kwargs.empty?
NamespaceHandle.new(
scoped_client: self,
namespace_proxy: resolve_namespace_proxy!(name)
)
rescue Errors::DiscoveryError
super
end
|
Instance Attribute Details
#provider ⇒ Object
Returns the value of attribute provider.
8
9
10
|
# File 'app/services/command_tower/clients/scoped_client.rb', line 8
def provider
@provider
end
|
#scope ⇒ Object
Returns the value of attribute scope.
8
9
10
|
# File 'app/services/command_tower/clients/scoped_client.rb', line 8
def scope
@scope
end
|
Instance Method Details
#[](key) ⇒ Object
23
24
25
|
# File 'app/services/command_tower/clients/scoped_client.rb', line 23
def [](key)
scope[key]
end
|
#decode_response(response) ⇒ Object
35
36
37
|
# File 'app/services/command_tower/clients/scoped_client.rb', line 35
def decode_response(response)
provider.decode_response(response)
end
|
#enforce_authentication! ⇒ Object
27
28
29
|
# File 'app/services/command_tower/clients/scoped_client.rb', line 27
def enforce_authentication!
provider.enforce_authentication!(**scope)
end
|
#execute(request) ⇒ Object
31
32
33
|
# File 'app/services/command_tower/clients/scoped_client.rb', line 31
def execute(request)
provider.execute(request, context: self)
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
50
51
52
53
54
55
|
# File 'app/services/command_tower/clients/scoped_client.rb', line 50
def respond_to_missing?(name, include_private = false)
resolve_namespace_proxy!(name)
true
rescue Errors::DiscoveryError
super
end
|
#user ⇒ Object
19
20
21
|
# File 'app/services/command_tower/clients/scoped_client.rb', line 19
def user
scope[:user]
end
|