Module: Smplkit::Config

Defined in:
lib/smplkit/config/client.rb,
lib/smplkit/config/models.rb,
lib/smplkit/config/helpers.rb

Defined Under Namespace

Modules: Discovery, Helpers, ItemType Classes: Config, ConfigChangeEvent, ConfigClient, ConfigEnvironment, ConfigItem, LiveConfigProxy

Class Method Summary collapse

Class Method Details

.config_transport(api_key:, base_url:, profile:, base_domain:, scheme:, debug:, extra_headers:) ⇒ Array(Object, String, String)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build a standalone config transport and resolve the app base URL.

base_url/api_key are used directly when supplied (the path a top-level client takes after it has already resolved them); otherwise the config resolver fills in whatever is missing (+~/.smplkit+ / env vars / defaults). The app base URL is returned alongside so a standalone client can open its own WebSocket against the event gateway.

Parameters:

  • api_key (String, nil)

    API key, or nil to resolve it.

  • base_url (String, nil)

    Full config-service base URL, or nil to resolve it from base_domain/scheme.

  • profile (String, nil)

    Named ~/.smplkit profile section.

  • base_domain (String, nil)

    Base domain for API requests.

  • scheme (String, nil)

    URL scheme.

  • debug (Boolean, nil)

    Enable SDK debug logging.

  • extra_headers (Hash{String => String}, nil)

    Headers attached to every request.

Returns:

  • (Array(Object, String, String))

    The transport, the app base URL, and the resolved API key.



355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'lib/smplkit/config/client.rb', line 355

def self.config_transport(api_key:, base_url:, profile:, base_domain:, scheme:, debug:, extra_headers:)
  cfg = ConfigResolution.resolve_client_config(
    profile: profile, api_key: api_key, base_domain: base_domain, scheme: scheme, debug: debug
  )
  resolved_key = api_key.nil? ? cfg.api_key : api_key
  merged = {}
  merged.merge!(cfg.extra_headers || {})
  merged.merge!(extra_headers || {})
  tcfg = ConfigResolution::ResolvedClientConfig.new(
    api_key: resolved_key, base_domain: cfg.base_domain, scheme: cfg.scheme,
    debug: cfg.debug, extra_headers: merged
  )
  app_url = ConfigResolution.service_url(cfg.scheme, "app", cfg.base_domain)
  transport = Transport.build_api_client(SmplkitGeneratedClient::Config, "config", tcfg, base_url: base_url)
  [transport, app_url, resolved_key]
end

.resolve_parent_id(parent) ⇒ String?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Normalize a parent argument to a config id string.

Parameters:

  • parent (String, Config, nil)

    A config id, a saved Config whose id is used, or nil.

Returns:

  • (String, nil)

    The resolved config id, or nil when parent is nil.

Raises:

  • (ArgumentError)

    If parent is an unsaved Config (no id yet).



326
327
328
329
330
331
332
333
# File 'lib/smplkit/config/client.rb', line 326

def self.resolve_parent_id(parent)
  return parent if parent.nil? || parent.is_a?(String)
  if parent.id.nil? || parent.id == ""
    raise ArgumentError, "parent config must be saved (have an id) before being used as a parent"
  end

  parent.id
end