Class: Quonfig::Client
- Inherits:
-
Object
- Object
- Quonfig::Client
- Defined in:
- lib/quonfig/client.rb
Overview
Public Quonfig SDK client.
Wires the new JSON stack: Quonfig::ConfigStore + Quonfig::Evaluator + Quonfig::Resolver. The legacy protobuf-driven ConfigClient/ConfigResolver path was removed in qfg-dk6.32. Network-mode (HTTP fetch + SSE updates) is not yet wired through Client; today the supported entry points are datadir: (offline workspace) and store: (caller-supplied Quonfig::ConfigStore, used by tests).
Constant Summary collapse
- LOG =
Quonfig::InternalLogger.new(self)
Instance Attribute Summary collapse
-
#evaluator ⇒ Object
readonly
Returns the value of attribute evaluator.
-
#instance_hash ⇒ Object
readonly
Returns the value of attribute instance_hash.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#resolver ⇒ Object
readonly
Returns the value of attribute resolver.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #defined?(key) ⇒ Boolean
- #enabled?(feature_name, jit_context = NO_DEFAULT_PROVIDED) ⇒ Boolean
- #fork ⇒ Object
-
#get(key, default = NO_DEFAULT_PROVIDED, jit_context = NO_DEFAULT_PROVIDED) ⇒ Object
—- Lookup ——————————————————–.
- #get_bool(key, default: NO_DEFAULT_PROVIDED, context: NO_DEFAULT_PROVIDED) ⇒ Object
- #get_duration(key, default: NO_DEFAULT_PROVIDED, context: NO_DEFAULT_PROVIDED) ⇒ Object
- #get_float(key, default: NO_DEFAULT_PROVIDED, context: NO_DEFAULT_PROVIDED) ⇒ Object
- #get_int(key, default: NO_DEFAULT_PROVIDED, context: NO_DEFAULT_PROVIDED) ⇒ Object
- #get_json(key, default: NO_DEFAULT_PROVIDED, context: NO_DEFAULT_PROVIDED) ⇒ Object
- #get_string(key, default: NO_DEFAULT_PROVIDED, context: NO_DEFAULT_PROVIDED) ⇒ Object
- #get_string_list(key, default: NO_DEFAULT_PROVIDED, context: NO_DEFAULT_PROVIDED) ⇒ Object
-
#in_context(properties) ⇒ Object
—- Context binding ———————————————-.
-
#initialize(options = nil, store: nil, **option_kwargs) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
- #keys ⇒ Object
- #on_update(&block) ⇒ Object
-
#semantic_logger_filter(config_key:) ⇒ Object
—- Filters & helpers ——————————————–.
- #stop ⇒ Object
- #with_context(properties, &block) ⇒ Object
Constructor Details
#initialize(options = nil, store: nil, **option_kwargs) ⇒ Client
Returns a new instance of Client.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/quonfig/client.rb', line 19 def initialize( = nil, store: nil, **option_kwargs) @options = if .is_a?(Quonfig::Options) elsif .is_a?(Hash) Quonfig::Options.new(.merge(option_kwargs)) else Quonfig::Options.new(option_kwargs) end @global_context = normalize_context(@options.global_context) @instance_hash = SecureRandom.uuid @store = store || build_store @evaluator = Quonfig::Evaluator.new(@store, env_id: @options.environment) @resolver = Quonfig::Resolver.new(@store, @evaluator) @semantic_logger_filters = {} end |
Instance Attribute Details
#evaluator ⇒ Object (readonly)
Returns the value of attribute evaluator.
17 18 19 |
# File 'lib/quonfig/client.rb', line 17 def evaluator @evaluator end |
#instance_hash ⇒ Object (readonly)
Returns the value of attribute instance_hash.
17 18 19 |
# File 'lib/quonfig/client.rb', line 17 def instance_hash @instance_hash end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'lib/quonfig/client.rb', line 17 def @options end |
#resolver ⇒ Object (readonly)
Returns the value of attribute resolver.
17 18 19 |
# File 'lib/quonfig/client.rb', line 17 def resolver @resolver end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
17 18 19 |
# File 'lib/quonfig/client.rb', line 17 def store @store end |
Instance Method Details
#defined?(key) ⇒ Boolean
79 80 81 |
# File 'lib/quonfig/client.rb', line 79 def defined?(key) !@store.get(key).nil? end |
#enabled?(feature_name, jit_context = NO_DEFAULT_PROVIDED) ⇒ Boolean
74 75 76 77 |
# File 'lib/quonfig/client.rb', line 74 def enabled?(feature_name, jit_context = NO_DEFAULT_PROVIDED) value = get(feature_name, false, jit_context) value == true || value == 'true' end |
#fork ⇒ Object
118 119 120 |
# File 'lib/quonfig/client.rb', line 118 def fork self.class.new(@options.for_fork) end |
#get(key, default = NO_DEFAULT_PROVIDED, jit_context = NO_DEFAULT_PROVIDED) ⇒ Object
—- Lookup ——————————————————–
38 39 40 41 42 43 44 |
# File 'lib/quonfig/client.rb', line 38 def get(key, default = NO_DEFAULT_PROVIDED, jit_context = NO_DEFAULT_PROVIDED) ctx = build_context(jit_context) result = @resolver.get(key, ctx) return handle_missing(key, default) if result.nil? result.unwrapped_value end |
#get_bool(key, default: NO_DEFAULT_PROVIDED, context: NO_DEFAULT_PROVIDED) ⇒ Object
58 59 60 |
# File 'lib/quonfig/client.rb', line 58 def get_bool(key, default: NO_DEFAULT_PROVIDED, context: NO_DEFAULT_PROVIDED) typed_get(key, :bool, default: default, context: context) end |
#get_duration(key, default: NO_DEFAULT_PROVIDED, context: NO_DEFAULT_PROVIDED) ⇒ Object
66 67 68 |
# File 'lib/quonfig/client.rb', line 66 def get_duration(key, default: NO_DEFAULT_PROVIDED, context: NO_DEFAULT_PROVIDED) typed_get(key, :duration, default: default, context: context) end |
#get_float(key, default: NO_DEFAULT_PROVIDED, context: NO_DEFAULT_PROVIDED) ⇒ Object
54 55 56 |
# File 'lib/quonfig/client.rb', line 54 def get_float(key, default: NO_DEFAULT_PROVIDED, context: NO_DEFAULT_PROVIDED) typed_get(key, Float, default: default, context: context) end |
#get_int(key, default: NO_DEFAULT_PROVIDED, context: NO_DEFAULT_PROVIDED) ⇒ Object
50 51 52 |
# File 'lib/quonfig/client.rb', line 50 def get_int(key, default: NO_DEFAULT_PROVIDED, context: NO_DEFAULT_PROVIDED) typed_get(key, Integer, default: default, context: context) end |
#get_json(key, default: NO_DEFAULT_PROVIDED, context: NO_DEFAULT_PROVIDED) ⇒ Object
70 71 72 |
# File 'lib/quonfig/client.rb', line 70 def get_json(key, default: NO_DEFAULT_PROVIDED, context: NO_DEFAULT_PROVIDED) typed_get(key, :json, default: default, context: context) end |
#get_string(key, default: NO_DEFAULT_PROVIDED, context: NO_DEFAULT_PROVIDED) ⇒ Object
46 47 48 |
# File 'lib/quonfig/client.rb', line 46 def get_string(key, default: NO_DEFAULT_PROVIDED, context: NO_DEFAULT_PROVIDED) typed_get(key, String, default: default, context: context) end |
#get_string_list(key, default: NO_DEFAULT_PROVIDED, context: NO_DEFAULT_PROVIDED) ⇒ Object
62 63 64 |
# File 'lib/quonfig/client.rb', line 62 def get_string_list(key, default: NO_DEFAULT_PROVIDED, context: NO_DEFAULT_PROVIDED) typed_get(key, :string_list, default: default, context: context) end |
#in_context(properties) ⇒ Object
—- Context binding ———————————————-
89 90 91 92 |
# File 'lib/quonfig/client.rb', line 89 def in_context(properties) bound = Quonfig::BoundClient.new(self, properties) block_given? ? yield(bound) : bound end |
#inspect ⇒ Object
122 123 124 |
# File 'lib/quonfig/client.rb', line 122 def inspect "#<Quonfig::Client:#{object_id} environment=#{@options.environment.inspect}>" end |
#keys ⇒ Object
83 84 85 |
# File 'lib/quonfig/client.rb', line 83 def keys @store.keys end |
#on_update(&block) ⇒ Object
109 110 111 |
# File 'lib/quonfig/client.rb', line 109 def on_update(&block) @on_update = block end |
#semantic_logger_filter(config_key:) ⇒ Object
—- Filters & helpers ——————————————–
104 105 106 107 |
# File 'lib/quonfig/client.rb', line 104 def semantic_logger_filter(config_key:) @semantic_logger_filters[config_key] ||= Quonfig::SemanticLoggerFilter.new(self, config_key: config_key) end |
#stop ⇒ Object
113 114 115 116 |
# File 'lib/quonfig/client.rb', line 113 def stop # No background threads in datadir mode; placeholder for the future # SSE/poll path so callers can use this method symmetrically. end |
#with_context(properties, &block) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/quonfig/client.rb', line 94 def with_context(properties, &block) if block_given? in_context(properties, &block) else Quonfig::BoundClient.new(self, properties) end end |