Class: OpenFeature::SDK::Configuration
- Inherits:
-
Object
- Object
- OpenFeature::SDK::Configuration
- Extended by:
- Forwardable
- Defined in:
- lib/open_feature/sdk/configuration.rb
Overview
Represents the configuration object for the global API where Provider
, Hook
, and EvaluationContext
are configured. This class is not meant to be interacted with directly but instead through the OpenFeature::SDK.configure
method
Instance Attribute Summary collapse
-
#evaluation_context ⇒ Object
Returns the value of attribute evaluation_context.
-
#hooks ⇒ Object
Returns the value of attribute hooks.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #provider(domain: nil) ⇒ Object
-
#set_provider(provider, domain: nil) ⇒ Object
When switching providers, there are a few lifecycle methods that need to be taken care of.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
16 17 18 19 20 |
# File 'lib/open_feature/sdk/configuration.rb', line 16 def initialize @hooks = [] @providers = {} @provider_mutex = Mutex.new end |
Instance Attribute Details
#evaluation_context ⇒ Object
Returns the value of attribute evaluation_context.
14 15 16 |
# File 'lib/open_feature/sdk/configuration.rb', line 14 def evaluation_context @evaluation_context end |
#hooks ⇒ Object
Returns the value of attribute hooks.
14 15 16 |
# File 'lib/open_feature/sdk/configuration.rb', line 14 def hooks @hooks end |
Instance Method Details
#provider(domain: nil) ⇒ Object
22 23 24 |
# File 'lib/open_feature/sdk/configuration.rb', line 22 def provider(domain: nil) @providers[domain] || @providers[nil] end |
#set_provider(provider, domain: nil) ⇒ Object
When switching providers, there are a few lifecycle methods that need to be taken care of.
1. If a provider is already set, we need to call `shutdown` on it.
2. On the new provider, call `init`.
3. Finally, set the internal provider to the new provider
30 31 32 33 34 35 36 37 38 |
# File 'lib/open_feature/sdk/configuration.rb', line 30 def set_provider(provider, domain: nil) @provider_mutex.synchronize do @providers[domain].shutdown if @providers[domain].respond_to?(:shutdown) provider.init if provider.respond_to?(:init) new_providers = @providers.dup new_providers[domain] = provider @providers = new_providers end end |