-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: Simplify folder structure for meta provider
Signed-off-by: Max VelDink <[email protected]>
- Loading branch information
1 parent
653036c
commit 0228eab
Showing
9 changed files
with
91 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 0 additions & 81 deletions
81
providers/openfeature-meta_provider/lib/open_feature/sdk/provider/meta_provider.rb
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
providers/openfeature-meta_provider/lib/open_feature/sdk/provider/version.rb
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
providers/openfeature-meta_provider/lib/openfeature/meta_provider.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# frozen_string_literal: true | ||
|
||
module OpenFeature | ||
# Used to pull from multiple providers. | ||
class MetaProvider | ||
# @param providers [Array<Provider>] | ||
# @param strategy [Symbol] When `:first_match`, returns first matched resolution. Providers will be searched | ||
# in the order they were given. Defaults to `:first_match`. | ||
def initialize(providers:, strategy: :first_match) | ||
@providers = providers | ||
@strategy = strategy | ||
end | ||
|
||
def metadata | ||
SDK::Provider::ProviderMetadata.new(name: "MetaProvider: #{providers.map { |provider| provider.metadata.name }.join(", ")}") | ||
end | ||
|
||
def init | ||
providers.each { |provider| provider.init } | ||
end | ||
|
||
def shutdown | ||
providers.each(&:shutdown) | ||
end | ||
|
||
def fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil) | ||
fetch_from_sources(default_value:) do |provider| | ||
provider.fetch_boolean_value(flag_key:, default_value:, evaluation_context:) | ||
end | ||
end | ||
|
||
def fetch_number_value(flag_key:, default_value:, evaluation_context: nil) | ||
fetch_from_sources(default_value:) do |provider| | ||
provider.fetch_number_value(flag_key:, default_value:, evaluation_context:) | ||
end | ||
end | ||
|
||
def fetch_object_value(flag_key:, default_value:, evaluation_context: nil) | ||
fetch_from_sources(default_value:) do |provider| | ||
provider.fetch_object_value(flag_key:, default_value:, evaluation_context:) | ||
end | ||
end | ||
|
||
def fetch_string_value(flag_key:, default_value:, evaluation_context: nil) | ||
fetch_from_sources(default_value:) do |provider| | ||
provider.fetch_string_value(flag_key:, default_value:, evaluation_context:) | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :providers, :strategy | ||
|
||
def fetch_from_sources(default_value:, &blk) | ||
case strategy | ||
when :first_match | ||
successful_details = providers.each do |provider| | ||
details = yield(provider) | ||
|
||
break details if details.error_code.nil? | ||
rescue | ||
next | ||
end | ||
|
||
if successful_details.is_a?(SDK::Provider::ResolutionDetails) | ||
successful_details | ||
else | ||
SDK::Provider::ResolutionDetails.new(value: default_value, error_code: SDK::Provider::ErrorCode::GENERAL, reason: SDK::Provider::Reason::ERROR) | ||
end | ||
else | ||
SDK::Provider::ResolutionDetails.new(value: default_value, error_code: SDK::Provider::ErrorCode::GENERAL, reason: "Unknown strategy for MetaProvider") | ||
end | ||
end | ||
end | ||
end |
3 changes: 3 additions & 0 deletions
3
providers/openfeature-meta_provider/lib/openfeature/meta_provider_version.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module OpenFeature | ||
META_PROVIDER_VERSION = "0.0.1" | ||
end |
4 changes: 2 additions & 2 deletions
4
providers/openfeature-meta_provider/openfeature-meta_provider.gemspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "lib/open_feature/sdk/provider/version" | ||
require_relative "lib/openfeature/meta_provider_version" | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = "openfeature-meta_provider" | ||
spec.version = OpenFeature::SDK::Provider::VERSION | ||
spec.version = OpenFeature::META_PROVIDER_VERSION | ||
spec.authors = ["OpenFeature Authors"] | ||
spec.email = ["[email protected]"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters