Module: Smplkit::Flags

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

Defined Under Namespace

Modules: Helpers, JsonLogicEvaluator Classes: BooleanFlag, Flag, FlagChangeEvent, FlagEnvironment, FlagRule, FlagStats, FlagValue, FlagsClient, JsonFlag, NumberFlag, ResolutionCache, StringFlag

Class Method Summary collapse

Class Method Details

.contexts_to_eval_dict(contexts) ⇒ Object

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.

Convert a list of Context objects to the nested evaluation dict.



120
121
122
# File 'lib/smplkit/flags/client.rb', line 120

def self.contexts_to_eval_dict(contexts)
  contexts.to_h { |ctx| [ctx.type, ctx.to_eval_hash] }
end

.deep_sort(value) ⇒ Object

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.



132
133
134
135
136
137
138
139
140
141
# File 'lib/smplkit/flags/client.rb', line 132

def self.deep_sort(value)
  case value
  when Hash
    value.keys.sort_by(&:to_s).to_h { |k| [k, deep_sort(value[k])] }
  when Array
    value.map { |v| deep_sort(v) }
  else
    value
  end
end

.flags_transport(api_key:, base_url:, profile:, base_domain:, scheme:, debug:, extra_headers:) ⇒ Object

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 standalone flags + app transports 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 management config resolver fills in whatever is missing (+~/.smplkit+ / env vars / defaults). The app transport backs the standalone contexts client (evaluation-context registration); the app base URL is returned so a standalone client can open its own WebSocket against the event gateway.



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/smplkit/flags/client.rb', line 153

def self.flags_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)
  flags_http = Transport.build_api_client(SmplkitGeneratedClient::Flags, "flags", tcfg, base_url: base_url)
  app_http = Transport.build_api_client(SmplkitGeneratedClient::App, "app", tcfg)
  [flags_http, app_http, app_url, resolved_key]
end

.hash_context(eval_dict) ⇒ Object

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.

Compute a stable hash for a context evaluation dict.



127
128
129
# File 'lib/smplkit/flags/client.rb', line 127

def self.hash_context(eval_dict)
  Digest::MD5.hexdigest(JSON.generate(deep_sort(eval_dict)))
end