Class: Quonfig::BoundClient

Inherits:
Object
  • Object
show all
Defined in:
lib/quonfig/bound_client.rb

Overview

Immutable context-bound view over a Quonfig::Client. Every lookup uses the bound context as the jit_context passed down to the resolver.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, context) ⇒ BoundClient

Returns a new instance of BoundClient.



9
10
11
12
13
# File 'lib/quonfig/bound_client.rb', line 9

def initialize(client, context)
  @client = client
  @context = context || {}
  freeze
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/quonfig/bound_client.rb', line 7

def client
  @client
end

#contextObject (readonly)

Returns the value of attribute context.



7
8
9
# File 'lib/quonfig/bound_client.rb', line 7

def context
  @context
end

Instance Method Details

#enabled?(feature_name) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/quonfig/bound_client.rb', line 43

def enabled?(feature_name)
  @client.enabled?(feature_name, @context)
end

#get_bool(key, default: NO_DEFAULT_PROVIDED) ⇒ Object



27
28
29
# File 'lib/quonfig/bound_client.rb', line 27

def get_bool(key, default: NO_DEFAULT_PROVIDED)
  @client.get_bool(key, default: default, context: @context)
end

#get_duration(key, default: NO_DEFAULT_PROVIDED) ⇒ Object



35
36
37
# File 'lib/quonfig/bound_client.rb', line 35

def get_duration(key, default: NO_DEFAULT_PROVIDED)
  @client.get_duration(key, default: default, context: @context)
end

#get_float(key, default: NO_DEFAULT_PROVIDED) ⇒ Object



23
24
25
# File 'lib/quonfig/bound_client.rb', line 23

def get_float(key, default: NO_DEFAULT_PROVIDED)
  @client.get_float(key, default: default, context: @context)
end

#get_int(key, default: NO_DEFAULT_PROVIDED) ⇒ Object



19
20
21
# File 'lib/quonfig/bound_client.rb', line 19

def get_int(key, default: NO_DEFAULT_PROVIDED)
  @client.get_int(key, default: default, context: @context)
end

#get_json(key, default: NO_DEFAULT_PROVIDED) ⇒ Object



39
40
41
# File 'lib/quonfig/bound_client.rb', line 39

def get_json(key, default: NO_DEFAULT_PROVIDED)
  @client.get_json(key, default: default, context: @context)
end

#get_string(key, default: NO_DEFAULT_PROVIDED) ⇒ Object



15
16
17
# File 'lib/quonfig/bound_client.rb', line 15

def get_string(key, default: NO_DEFAULT_PROVIDED)
  @client.get_string(key, default: default, context: @context)
end

#get_string_list(key, default: NO_DEFAULT_PROVIDED) ⇒ Object



31
32
33
# File 'lib/quonfig/bound_client.rb', line 31

def get_string_list(key, default: NO_DEFAULT_PROVIDED)
  @client.get_string_list(key, default: default, context: @context)
end

#in_context(additional) ⇒ Object

Returns a new BoundClient whose bound context is the merge of this bound context and additional. Merge is one level deep per named context (mirrors sdk-node’s mergeContexts): later values override earlier within the same named context; keys unique to each side are preserved.



52
53
54
# File 'lib/quonfig/bound_client.rb', line 52

def in_context(additional)
  self.class.new(@client, merge_contexts(@context, additional || {}))
end

#inspectObject



56
57
58
# File 'lib/quonfig/bound_client.rb', line 56

def inspect
  "#<Quonfig::BoundClient context=#{@context.inspect}>"
end