Class: CommandTower::Clients::NamespaceProxy

Inherits:
Object
  • Object
show all
Defined in:
app/services/command_tower/clients/namespace_proxy.rb

Overview

Lightweight handle for a Zeitwerk namespace module under a provider. Internal resolution primitive — not the locked product invocation API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:, namespace_module:) ⇒ NamespaceProxy

Returns a new instance of NamespaceProxy.



10
11
12
13
14
15
16
17
18
19
# File 'app/services/command_tower/clients/namespace_proxy.rb', line 10

def initialize(client:, namespace_module:)
  raise Errors::ConfigurationError, "client is required" if client.nil?
  raise Errors::ConfigurationError, "namespace_module is required" if namespace_module.nil?

  @client = client
  @namespace_module = namespace_module
  @endpoint_mutex = Mutex.new
  @endpoints = {}
  @endpoint_classes = {}
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



8
9
10
# File 'app/services/command_tower/clients/namespace_proxy.rb', line 8

def client
  @client
end

#namespace_moduleObject (readonly)

Returns the value of attribute namespace_module.



8
9
10
# File 'app/services/command_tower/clients/namespace_proxy.rb', line 8

def namespace_module
  @namespace_module
end

Instance Method Details

#build_endpoint(name, client:) ⇒ Object

Memoize endpoint class resolution only; always return a fresh instance.



35
36
37
38
# File 'app/services/command_tower/clients/namespace_proxy.rb', line 35

def build_endpoint(name, client:)
  klass = resolve_endpoint_class!(name)
  build_endpoint_instance!(klass, client: client)
end

#resolve_endpoint!(name) ⇒ Object

Resolve and memoize an EndpointBase instance bound to this proxy's client. Prefer #build_endpoint for ScopedClient so user-bound instances are not shared.



23
24
25
26
27
28
29
30
31
32
# File 'app/services/command_tower/clients/namespace_proxy.rb', line 23

def resolve_endpoint!(name)
  const_name = ConstResolution.normalize_name(name)

  @endpoint_mutex.synchronize do
    @endpoints[const_name] ||= build_endpoint_instance!(
      resolve_endpoint_class_locked!(const_name),
      client: client
    )
  end
end

#resolve_endpoint_class!(name) ⇒ Object



40
41
42
43
44
45
46
# File 'app/services/command_tower/clients/namespace_proxy.rb', line 40

def resolve_endpoint_class!(name)
  const_name = ConstResolution.normalize_name(name)

  @endpoint_mutex.synchronize do
    resolve_endpoint_class_locked!(const_name)
  end
end