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
-
.contexts_to_eval_dict(contexts) ⇒ Object
Convert a list of Context objects to the nested evaluation dict.
- .deep_sort(value) ⇒ Object
-
.flags_transport(api_key:, base_url:, profile:, base_domain:, scheme:, debug:, extra_headers:) ⇒ Object
Build standalone flags + app transports and resolve the app base URL.
-
.hash_context(eval_dict) ⇒ Object
Compute a stable hash for a context evaluation dict.
Class Method Details
.contexts_to_eval_dict(contexts) ⇒ Object
Convert a list of Context objects to the nested evaluation dict.
102 103 104 |
# File 'lib/smplkit/flags/client.rb', line 102 def self.contexts_to_eval_dict(contexts) contexts.to_h { |ctx| [ctx.type, ctx.to_eval_hash] } end |
.deep_sort(value) ⇒ Object
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/smplkit/flags/client.rb', line 111 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
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.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/smplkit/flags/client.rb', line 130 def self.flags_transport(api_key:, base_url:, profile:, base_domain:, scheme:, debug:, extra_headers:) cfg = ConfigResolution.resolve_management_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::ResolvedManagementConfig.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
Compute a stable hash for a context evaluation dict.
107 108 109 |
# File 'lib/smplkit/flags/client.rb', line 107 def self.hash_context(eval_dict) Digest::MD5.hexdigest(JSON.generate(deep_sort(eval_dict))) end |