Class: Quonfig::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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(options = nil, store: nil, **option_kwargs)
  @options =
    if options.is_a?(Quonfig::Options)
      options
    elsif options.is_a?(Hash)
      Quonfig::Options.new(options.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

#evaluatorObject (readonly)

Returns the value of attribute evaluator.



17
18
19
# File 'lib/quonfig/client.rb', line 17

def evaluator
  @evaluator
end

#instance_hashObject (readonly)

Returns the value of attribute instance_hash.



17
18
19
# File 'lib/quonfig/client.rb', line 17

def instance_hash
  @instance_hash
end

#optionsObject (readonly)

Returns the value of attribute options.



17
18
19
# File 'lib/quonfig/client.rb', line 17

def options
  @options
end

#resolverObject (readonly)

Returns the value of attribute resolver.



17
18
19
# File 'lib/quonfig/client.rb', line 17

def resolver
  @resolver
end

#storeObject (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

Returns:

  • (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

Returns:

  • (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

#forkObject



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

#inspectObject



122
123
124
# File 'lib/quonfig/client.rb', line 122

def inspect
  "#<Quonfig::Client:#{object_id} environment=#{@options.environment.inspect}>"
end

#keysObject



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

#stopObject



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