Class: Quonfig::BoundClient
- Inherits:
-
Object
- Object
- Quonfig::BoundClient
- 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
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
- #enabled?(feature_name) ⇒ Boolean
- #get_bool(key, default: NO_DEFAULT_PROVIDED) ⇒ Object
- #get_duration(key, default: NO_DEFAULT_PROVIDED) ⇒ Object
- #get_float(key, default: NO_DEFAULT_PROVIDED) ⇒ Object
- #get_int(key, default: NO_DEFAULT_PROVIDED) ⇒ Object
- #get_json(key, default: NO_DEFAULT_PROVIDED) ⇒ Object
- #get_string(key, default: NO_DEFAULT_PROVIDED) ⇒ Object
- #get_string_list(key, default: NO_DEFAULT_PROVIDED) ⇒ Object
-
#in_context(additional) ⇒ Object
Returns a new BoundClient whose bound context is the merge of this bound context and
additional. -
#initialize(client, context) ⇒ BoundClient
constructor
A new instance of BoundClient.
- #inspect ⇒ Object
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
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/quonfig/bound_client.rb', line 7 def client @client end |
#context ⇒ Object (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
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 |
#inspect ⇒ Object
56 57 58 |
# File 'lib/quonfig/bound_client.rb', line 56 def inspect "#<Quonfig::BoundClient context=#{@context.inspect}>" end |