Class: OpenFeatureSorbet::MultipleSourceProvider
- Extended by:
- T::Sig
- Defined in:
- lib/open_feature_sorbet/multiple_source_provider.rb
Overview
Used to pull from multiple providers. Order of the providers given to initialize matters. The providers will be evaluated in that order and the first non-error result will be used. If all sources return an error then the default value is used.
Instance Attribute Summary
Attributes inherited from Provider
Instance Method Summary collapse
- #hooks ⇒ Object
- #init(context:) ⇒ Object
-
#initialize(providers:) ⇒ MultipleSourceProvider
constructor
A new instance of MultipleSourceProvider.
- #metadata ⇒ Object
- #resolve_boolean_value(flag_key:, default_value:, context: nil) ⇒ Object
- #resolve_number_value(flag_key:, default_value:, context: nil) ⇒ Object
- #resolve_string_value(flag_key:, default_value:, context: nil) ⇒ Object
- #resolve_structure_value(flag_key:, default_value:, context: nil) ⇒ Object
- #shutdown ⇒ Object
Constructor Details
#initialize(providers:) ⇒ MultipleSourceProvider
Returns a new instance of MultipleSourceProvider.
14 15 16 17 |
# File 'lib/open_feature_sorbet/multiple_source_provider.rb', line 14 def initialize(providers:) @providers = providers super(ProviderStatus::NotReady) end |
Instance Method Details
#hooks ⇒ Object
25 26 27 |
# File 'lib/open_feature_sorbet/multiple_source_provider.rb', line 25 def hooks providers.flat_map(&:hooks) end |
#init(context:) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/open_feature_sorbet/multiple_source_provider.rb', line 30 def init(context:) providers.each { |provider| provider.init(context: context) } @status = if providers.all? { |provider| provider.status == ProviderStatus::Ready } ProviderStatus::Ready else ProviderStatus::Error end rescue StandardError @status = ProviderStatus::Error end |
#metadata ⇒ Object
20 21 22 |
# File 'lib/open_feature_sorbet/multiple_source_provider.rb', line 20 def ProviderMetadata.new(name: "Multiple Sources: #{providers.map { |provider| provider..name }.join(", ")}") end |
#resolve_boolean_value(flag_key:, default_value:, context: nil) ⇒ Object
55 56 57 58 59 |
# File 'lib/open_feature_sorbet/multiple_source_provider.rb', line 55 def resolve_boolean_value(flag_key:, default_value:, context: nil) resolve_from_sources(default_value: default_value) do |provider| provider.resolve_boolean_value(flag_key: flag_key, default_value: default_value, context: context) end end |
#resolve_number_value(flag_key:, default_value:, context: nil) ⇒ Object
70 71 72 73 74 |
# File 'lib/open_feature_sorbet/multiple_source_provider.rb', line 70 def resolve_number_value(flag_key:, default_value:, context: nil) resolve_from_sources(default_value: default_value) do |provider| provider.resolve_number_value(flag_key: flag_key, default_value: default_value, context: context) end end |
#resolve_string_value(flag_key:, default_value:, context: nil) ⇒ Object
100 101 102 103 104 |
# File 'lib/open_feature_sorbet/multiple_source_provider.rb', line 100 def resolve_string_value(flag_key:, default_value:, context: nil) resolve_from_sources(default_value: default_value) do |provider| provider.resolve_string_value(flag_key: flag_key, default_value: default_value, context: context) end end |
#resolve_structure_value(flag_key:, default_value:, context: nil) ⇒ Object
85 86 87 88 89 |
# File 'lib/open_feature_sorbet/multiple_source_provider.rb', line 85 def resolve_structure_value(flag_key:, default_value:, context: nil) resolve_from_sources(default_value: default_value) do |provider| provider.resolve_structure_value(flag_key: flag_key, default_value: default_value, context: context) end end |
#shutdown ⇒ Object
42 43 44 |
# File 'lib/open_feature_sorbet/multiple_source_provider.rb', line 42 def shutdown providers.each(&:shutdown) end |