openfeature-meta_provider 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '0813bb863d90dd6129d96e10d5f3749d8a5b4ce62f4a58cc0bf2d89f42f12c2c'
4
+ data.tar.gz: 5b2eaaef9f874526f1fe63018f19b4b7ae58669eb657176cb1144446fee81c3b
5
+ SHA512:
6
+ metadata.gz: b884b1381e5195fbcb5a3a3cc4ef458e7d1bf7f497ef7ba743a0198e6671c6f4a8230be6704ec74b27be99a9896dfb650a462d4f1ee277118a65c56e2b4992f2
7
+ data.tar.gz: bb537857166ac47fb984977e6e55a561d297449e66a13f8dee5e225d68fb6e4a74ac8b0bc94079ea1be97da645beb39f2cfa400ad4986758571b11a6e13ad774
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ spec/examples.txt
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ -I lib
2
+ --format documentation
3
+ --color
4
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.3.0
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ parallel: true
2
+ format: progress
3
+ ruby_version: 3.1
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.3.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+
3
+ ## [0.0.3](https://github.com/open-feature/ruby-sdk-contrib/compare/openfeature-meta_provider/v0.0.2...openfeature-meta_provider/v0.0.3) (2024-05-16)
4
+
5
+
6
+ ### 🧹 Chore
7
+
8
+ * update readme title ([#34](https://github.com/open-feature/ruby-sdk-contrib/issues/34)) ([06f1517](https://github.com/open-feature/ruby-sdk-contrib/commit/06f1517f0e384b6b86d5aa7caedc6c3fd0bd74c7))
9
+
10
+ ## [0.0.2](https://github.com/open-feature/ruby-sdk-contrib/compare/openfeature-meta_provider-v0.0.1...openfeature-meta_provider/v0.0.2) (2024-05-14)
11
+
12
+
13
+ ### ✨ New Features
14
+
15
+ * add matched provider to flag metadata in MetaProvider ([#31](https://github.com/open-feature/ruby-sdk-contrib/issues/31)) ([d48b182](https://github.com/open-feature/ruby-sdk-contrib/commit/d48b18253c1e23ac35c4d75edaaa7b89c6cc504b))
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in openfeature-meta_provider.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,95 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ openfeature-meta_provider (0.0.3)
5
+ openfeature-sdk (~> 0.3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ debug (1.9.2)
12
+ irb (~> 1.10)
13
+ reline (>= 0.3.8)
14
+ diff-lcs (1.5.1)
15
+ io-console (0.7.2)
16
+ irb (1.12.0)
17
+ rdoc
18
+ reline (>= 0.4.2)
19
+ json (2.7.2)
20
+ language_server-protocol (3.17.0.3)
21
+ lint_roller (1.1.0)
22
+ openfeature-sdk (0.3.0)
23
+ parallel (1.24.0)
24
+ parser (3.3.0.5)
25
+ ast (~> 2.4.1)
26
+ racc
27
+ psych (5.1.2)
28
+ stringio
29
+ racc (1.7.3)
30
+ rainbow (3.1.1)
31
+ rake (13.2.1)
32
+ rdoc (6.6.3.1)
33
+ psych (>= 4.0.0)
34
+ regexp_parser (2.9.0)
35
+ reline (0.5.0)
36
+ io-console (~> 0.5)
37
+ rexml (3.2.6)
38
+ rspec (3.13.0)
39
+ rspec-core (~> 3.13.0)
40
+ rspec-expectations (~> 3.13.0)
41
+ rspec-mocks (~> 3.13.0)
42
+ rspec-core (3.13.0)
43
+ rspec-support (~> 3.13.0)
44
+ rspec-expectations (3.13.0)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.13.0)
47
+ rspec-mocks (3.13.0)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.13.0)
50
+ rspec-support (3.13.1)
51
+ rubocop (1.62.1)
52
+ json (~> 2.3)
53
+ language_server-protocol (>= 3.17.0)
54
+ parallel (~> 1.10)
55
+ parser (>= 3.3.0.2)
56
+ rainbow (>= 2.2.2, < 4.0)
57
+ regexp_parser (>= 1.8, < 3.0)
58
+ rexml (>= 3.2.5, < 4.0)
59
+ rubocop-ast (>= 1.31.1, < 2.0)
60
+ ruby-progressbar (~> 1.7)
61
+ unicode-display_width (>= 2.4.0, < 3.0)
62
+ rubocop-ast (1.31.2)
63
+ parser (>= 3.3.0.4)
64
+ rubocop-performance (1.20.2)
65
+ rubocop (>= 1.48.1, < 2.0)
66
+ rubocop-ast (>= 1.30.0, < 2.0)
67
+ ruby-progressbar (1.13.0)
68
+ standard (1.35.1)
69
+ language_server-protocol (~> 3.17.0.2)
70
+ lint_roller (~> 1.0)
71
+ rubocop (~> 1.62.0)
72
+ standard-custom (~> 1.0.0)
73
+ standard-performance (~> 1.3)
74
+ standard-custom (1.0.2)
75
+ lint_roller (~> 1.0)
76
+ rubocop (~> 1.50)
77
+ standard-performance (1.3.1)
78
+ lint_roller (~> 1.1)
79
+ rubocop-performance (~> 1.20.2)
80
+ stringio (3.1.0)
81
+ unicode-display_width (2.5.0)
82
+
83
+ PLATFORMS
84
+ arm64-darwin-23
85
+ ruby
86
+
87
+ DEPENDENCIES
88
+ debug (~> 1.9.2)
89
+ openfeature-meta_provider!
90
+ rake (~> 13.0)
91
+ rspec (~> 3.12)
92
+ standard (~> 1.34)
93
+
94
+ BUNDLED WITH
95
+ 2.5.6
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # OpenFeature Meta-Provider for Ruby
2
+
3
+ The `OpenFeature::SDK::Provider::MetaProvider` is a utility provider implementation that takes multiple [providers](https://docs.openfeature.dev/docs/specification/sections/providers) for use during flag resolution. This can be helpful when an organization is migrating or consolidating feature flag providers as they transition to OpenFeature. There are usually a combination of internal and vendor providers that are combined together to handle flag resolution. If your organization has different providers for different teams, consider looking at using [domains](https://openfeature.dev/specification/glossary#domain).
4
+
5
+ ## Installation
6
+
7
+ Coming soon!
8
+
9
+ ## Usage
10
+
11
+ The `MetaProvider` is initialized with a collection of `Provider`s and a strategy for fetching flags from them.
12
+
13
+ ```ruby
14
+ # Create a MetaProvider
15
+ meta_provider = OpenFeature::SDK::Provider::MetaProvider.new(
16
+ providers: [
17
+ OpenFeature::SDK::ProviderInMemoryProvider.new,
18
+ MyCustomProvider.new
19
+ ],
20
+ strategy: :first_match
21
+ )
22
+
23
+ # Use it as the default provider
24
+ OpenFeature.configure do |c|
25
+ c.set_provider(meta_provider)
26
+ end
27
+ ```
28
+
29
+ ### Strategies
30
+
31
+ #### :first_match
32
+
33
+ When `:first_match` is given as the strategy, each provider will be evaluated, in the order they were passed in, for the requested `flag_key`. The first provider where the `flag_key` is found will be returned, short-circuiting flag evaluation with the remaining providers. In the case of a provider error, or no matching flags, returns the default value.
34
+
35
+
36
+ ## Contributing
37
+
38
+ https://github.com/open-feature/ruby-sdk-contrib
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[standard spec]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "open_feature/sdk/provider/meta_provider"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/rake ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12
+
13
+ bundle_binstub = File.expand_path("bundle", __dir__)
14
+
15
+ if File.file?(bundle_binstub)
16
+ if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
17
+ load(bundle_binstub)
18
+ else
19
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
20
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
21
+ end
22
+ end
23
+
24
+ require "rubygems"
25
+ require "bundler/setup"
26
+
27
+ load Gem.bin_path("rake", "rake")
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenFeature
4
+ # Used to pull from multiple providers.
5
+ class MetaProvider
6
+ # @param providers [Array<Provider>]
7
+ # @param strategy [Symbol] When `:first_match`, returns first matched resolution. Providers will be searched
8
+ # in the order they were given. Defaults to `:first_match`.
9
+ def initialize(providers:, strategy: :first_match)
10
+ @providers = providers
11
+ @strategy = strategy
12
+ end
13
+
14
+ def metadata
15
+ SDK::Provider::ProviderMetadata.new(name: "MetaProvider: #{providers.map { |provider| provider.metadata.name }.join(", ")}")
16
+ end
17
+
18
+ def init
19
+ providers.each { |provider| provider.init }
20
+ end
21
+
22
+ def shutdown
23
+ providers.each(&:shutdown)
24
+ end
25
+
26
+ def fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil)
27
+ fetch_from_sources(default_value:) do |provider|
28
+ provider.fetch_boolean_value(flag_key:, default_value:, evaluation_context:)
29
+ end
30
+ end
31
+
32
+ def fetch_number_value(flag_key:, default_value:, evaluation_context: nil)
33
+ fetch_from_sources(default_value:) do |provider|
34
+ provider.fetch_number_value(flag_key:, default_value:, evaluation_context:)
35
+ end
36
+ end
37
+
38
+ def fetch_object_value(flag_key:, default_value:, evaluation_context: nil)
39
+ fetch_from_sources(default_value:) do |provider|
40
+ provider.fetch_object_value(flag_key:, default_value:, evaluation_context:)
41
+ end
42
+ end
43
+
44
+ def fetch_string_value(flag_key:, default_value:, evaluation_context: nil)
45
+ fetch_from_sources(default_value:) do |provider|
46
+ provider.fetch_string_value(flag_key:, default_value:, evaluation_context:)
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ attr_reader :providers, :strategy
53
+
54
+ def fetch_from_sources(default_value:, &blk)
55
+ case strategy
56
+ when :first_match
57
+ successful_details = providers.each do |provider|
58
+ details = yield(provider)
59
+
60
+ details = SDK::Provider::ResolutionDetails.new(
61
+ value: details.value,
62
+ reason: details.reason,
63
+ variant: details.variant,
64
+ error_code: details.error_code,
65
+ error_message: details.error_message,
66
+ flag_metadata: (details.flag_metadata || {}).merge("matched_provider" => provider.metadata.name)
67
+ )
68
+
69
+ break details if details.error_code.nil?
70
+ rescue
71
+ next
72
+ end
73
+
74
+ if successful_details.is_a?(SDK::Provider::ResolutionDetails)
75
+ successful_details
76
+ else
77
+ SDK::Provider::ResolutionDetails.new(value: default_value, error_code: SDK::Provider::ErrorCode::GENERAL, reason: SDK::Provider::Reason::ERROR)
78
+ end
79
+ else
80
+ SDK::Provider::ResolutionDetails.new(value: default_value, error_code: SDK::Provider::ErrorCode::GENERAL, reason: "Unknown strategy for MetaProvider")
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,3 @@
1
+ module OpenFeature
2
+ META_PROVIDER_VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/openfeature/meta_provider_version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "openfeature-meta_provider"
7
+ spec.version = OpenFeature::META_PROVIDER_VERSION
8
+ spec.authors = ["OpenFeature Authors"]
9
+ spec.email = ["cncf-openfeature-contributors@lists.cncf.io"]
10
+
11
+ spec.summary = "Meta provider for the OpenFeature Ruby SDK"
12
+ spec.description = "The MetaProvider wraps multiple other providers and uses a given strategy to resolve flags using all of them."
13
+ spec.homepage = "https://github.com/open-feature/ruby-sdk-contrib/providers/openfeature-meta_provider"
14
+ spec.license = "Apache-2.0"
15
+ spec.required_ruby_version = ">= 3.1"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/open-feature/ruby-sdk-contrib/providers/openfeature-meta_provider"
19
+ spec.metadata["changelog_uri"] = "https://github.com/open-feature/ruby-sdk-contrib/blob/main/providers/openfeature-meta_provider/CHANGELOG.md"
20
+ spec.metadata["bug_tracker_uri"] = "https://github.com/open-feature/ruby-sdk-contrib/issues"
21
+ spec.metadata["documentation_uri"] = "https://github.com/open-feature/ruby-sdk-contrib/README.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency "openfeature-sdk", "~> 0.3.0"
33
+
34
+ spec.add_development_dependency "rake", "~> 13.0"
35
+ spec.add_development_dependency "rspec", "~> 3.12"
36
+ spec.add_development_dependency "standard", "~> 1.34"
37
+ spec.add_development_dependency "debug", "~> 1.9.2"
38
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openfeature-meta_provider
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - OpenFeature Authors
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-05-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: openfeature-sdk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: standard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.34'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.34'
69
+ - !ruby/object:Gem::Dependency
70
+ name: debug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.9.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.9.2
83
+ description: The MetaProvider wraps multiple other providers and uses a given strategy
84
+ to resolve flags using all of them.
85
+ email:
86
+ - cncf-openfeature-contributors@lists.cncf.io
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".ruby-version"
94
+ - ".standard.yml"
95
+ - ".tool-versions"
96
+ - CHANGELOG.md
97
+ - Gemfile
98
+ - Gemfile.lock
99
+ - README.md
100
+ - Rakefile
101
+ - bin/console
102
+ - bin/rake
103
+ - bin/setup
104
+ - lib/openfeature/meta_provider.rb
105
+ - lib/openfeature/meta_provider_version.rb
106
+ - openfeature-meta_provider.gemspec
107
+ homepage: https://github.com/open-feature/ruby-sdk-contrib/providers/openfeature-meta_provider
108
+ licenses:
109
+ - Apache-2.0
110
+ metadata:
111
+ homepage_uri: https://github.com/open-feature/ruby-sdk-contrib/providers/openfeature-meta_provider
112
+ source_code_uri: https://github.com/open-feature/ruby-sdk-contrib/providers/openfeature-meta_provider
113
+ changelog_uri: https://github.com/open-feature/ruby-sdk-contrib/blob/main/providers/openfeature-meta_provider/CHANGELOG.md
114
+ bug_tracker_uri: https://github.com/open-feature/ruby-sdk-contrib/issues
115
+ documentation_uri: https://github.com/open-feature/ruby-sdk-contrib/README.md
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '3.1'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubygems_version: 3.5.9
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Meta provider for the OpenFeature Ruby SDK
135
+ test_files: []