openfeature-ruby-sdk-contrib 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +55 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +97 -0
- data/LICENSE.txt +21 -0
- data/README.md +85 -0
- data/Rakefile +12 -0
- data/lib/open_feature/sdk/contrib/providers/common.rb +156 -0
- data/lib/open_feature/sdk/contrib/providers/file_provider.rb +44 -0
- data/lib/open_feature/sdk/contrib/version.rb +9 -0
- data/lib/open_feature/sdk/contrib.rb +13 -0
- metadata +211 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ce92cec4c5146fcee215e7edca3f4daf9757a1cd4fda456176d197c861b0c620
|
|
4
|
+
data.tar.gz: bbfd473392d8143ae247ac862a6f6e591bb6e679d6bfad309bfb4ecf78f78976
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d19265c25e33347ecb64eb29bd7d31384bd739a2e24564d7176feb60d51c34d0d5fef9190964fd67bd7c04672be7afad9926cabc9ad20fdbeb6293a6232f7f28
|
|
7
|
+
data.tar.gz: 757c5224f87fc475635c64b44c36fc87a8a183f6c51a225d207a9f437e89d54a15bb0606b72b8946e4753c372ad07d303e9e8a2cbe88d16a06b5c70d66e208c7
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require:
|
|
2
|
+
- rubocop-performance
|
|
3
|
+
- standard
|
|
4
|
+
- rubocop-rspec
|
|
5
|
+
- rubocop-rake
|
|
6
|
+
|
|
7
|
+
AllCops:
|
|
8
|
+
NewCops: enable
|
|
9
|
+
TargetRubyVersion: 3.0
|
|
10
|
+
|
|
11
|
+
Layout/ArgumentAlignment:
|
|
12
|
+
EnforcedStyle: with_first_argument
|
|
13
|
+
|
|
14
|
+
Layout/ExtraSpacing:
|
|
15
|
+
Enabled: true
|
|
16
|
+
ForceEqualSignAlignment: true
|
|
17
|
+
|
|
18
|
+
Layout/HashAlignment:
|
|
19
|
+
Enabled: true
|
|
20
|
+
EnforcedColonStyle: table
|
|
21
|
+
EnforcedHashRocketStyle: table
|
|
22
|
+
EnforcedLastArgumentHashStyle: ignore_implicit
|
|
23
|
+
|
|
24
|
+
Layout/LineLength:
|
|
25
|
+
Enabled: false
|
|
26
|
+
|
|
27
|
+
Layout/SpaceInsideHashLiteralBraces:
|
|
28
|
+
EnforcedStyle: compact
|
|
29
|
+
|
|
30
|
+
Lint/UnusedMethodArgument:
|
|
31
|
+
Enabled: false
|
|
32
|
+
|
|
33
|
+
Metrics/AbcSize:
|
|
34
|
+
Enabled: false
|
|
35
|
+
|
|
36
|
+
Metrics/CyclomaticComplexity:
|
|
37
|
+
Enabled: false
|
|
38
|
+
|
|
39
|
+
Metrics/PerceivedComplexity:
|
|
40
|
+
Enabled: false
|
|
41
|
+
|
|
42
|
+
RSpec/MessageSpies:
|
|
43
|
+
Enabled: false
|
|
44
|
+
|
|
45
|
+
RSpec/MultipleExpectations:
|
|
46
|
+
Enabled: false
|
|
47
|
+
|
|
48
|
+
Standard/SemanticBlocks:
|
|
49
|
+
Enabled: false
|
|
50
|
+
|
|
51
|
+
Style/StringLiterals:
|
|
52
|
+
Enabled: false
|
|
53
|
+
|
|
54
|
+
Style/TernaryParentheses:
|
|
55
|
+
Enabled: false
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
openfeature-ruby-sdk-contrib (0.1.0)
|
|
5
|
+
concurrent-ruby (~> 1.2.2)
|
|
6
|
+
faraday (~> 2.7.4)
|
|
7
|
+
openfeature-sdk (~> 0.1)
|
|
8
|
+
|
|
9
|
+
GEM
|
|
10
|
+
remote: https://rubygems.org/
|
|
11
|
+
specs:
|
|
12
|
+
ast (2.4.2)
|
|
13
|
+
byebug (11.1.3)
|
|
14
|
+
coderay (1.1.3)
|
|
15
|
+
concurrent-ruby (1.2.2)
|
|
16
|
+
diff-lcs (1.5.0)
|
|
17
|
+
faraday (2.7.4)
|
|
18
|
+
faraday-net_http (>= 2.0, < 3.1)
|
|
19
|
+
ruby2_keywords (>= 0.0.4)
|
|
20
|
+
faraday-net_http (3.0.2)
|
|
21
|
+
json (2.6.3)
|
|
22
|
+
method_source (1.0.0)
|
|
23
|
+
openfeature-sdk (0.1.0)
|
|
24
|
+
parallel (1.22.1)
|
|
25
|
+
parser (3.2.1.0)
|
|
26
|
+
ast (~> 2.4.1)
|
|
27
|
+
pry (0.14.1)
|
|
28
|
+
coderay (~> 1.1)
|
|
29
|
+
method_source (~> 1.0)
|
|
30
|
+
pry-byebug (3.10.1)
|
|
31
|
+
byebug (~> 11.0)
|
|
32
|
+
pry (>= 0.13, < 0.15)
|
|
33
|
+
rainbow (3.1.1)
|
|
34
|
+
rake (13.0.6)
|
|
35
|
+
regexp_parser (2.7.0)
|
|
36
|
+
rexml (3.2.5)
|
|
37
|
+
rspec (3.11.0)
|
|
38
|
+
rspec-core (~> 3.11.0)
|
|
39
|
+
rspec-expectations (~> 3.11.0)
|
|
40
|
+
rspec-mocks (~> 3.11.0)
|
|
41
|
+
rspec-core (3.11.0)
|
|
42
|
+
rspec-support (~> 3.11.0)
|
|
43
|
+
rspec-expectations (3.11.1)
|
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
45
|
+
rspec-support (~> 3.11.0)
|
|
46
|
+
rspec-mocks (3.11.1)
|
|
47
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
48
|
+
rspec-support (~> 3.11.0)
|
|
49
|
+
rspec-support (3.11.1)
|
|
50
|
+
rubocop (1.48.0)
|
|
51
|
+
json (~> 2.3)
|
|
52
|
+
parallel (~> 1.10)
|
|
53
|
+
parser (>= 3.2.0.0)
|
|
54
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
55
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
56
|
+
rexml (>= 3.2.5, < 4.0)
|
|
57
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
|
58
|
+
ruby-progressbar (~> 1.7)
|
|
59
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
|
60
|
+
rubocop-ast (1.27.0)
|
|
61
|
+
parser (>= 3.2.1.0)
|
|
62
|
+
rubocop-capybara (2.17.1)
|
|
63
|
+
rubocop (~> 1.41)
|
|
64
|
+
rubocop-performance (1.15.2)
|
|
65
|
+
rubocop (>= 1.7.0, < 2.0)
|
|
66
|
+
rubocop-ast (>= 0.4.0)
|
|
67
|
+
rubocop-rake (0.6.0)
|
|
68
|
+
rubocop (~> 1.0)
|
|
69
|
+
rubocop-rspec (2.19.0)
|
|
70
|
+
rubocop (~> 1.33)
|
|
71
|
+
rubocop-capybara (~> 2.17)
|
|
72
|
+
ruby-progressbar (1.13.0)
|
|
73
|
+
ruby2_keywords (0.0.5)
|
|
74
|
+
standard (0.0.36)
|
|
75
|
+
rubocop (>= 0.63)
|
|
76
|
+
unicode-display_width (2.4.2)
|
|
77
|
+
webrick (1.7.0)
|
|
78
|
+
yard (0.9.28)
|
|
79
|
+
webrick (~> 1.7.0)
|
|
80
|
+
|
|
81
|
+
PLATFORMS
|
|
82
|
+
arm64-darwin-22
|
|
83
|
+
|
|
84
|
+
DEPENDENCIES
|
|
85
|
+
openfeature-ruby-sdk-contrib!
|
|
86
|
+
pry-byebug (~> 3.10.1)
|
|
87
|
+
rake (~> 13.0)
|
|
88
|
+
rspec (~> 3.0)
|
|
89
|
+
rubocop (~> 1.21)
|
|
90
|
+
rubocop-performance (~> 1.15)
|
|
91
|
+
rubocop-rake (~> 0.6)
|
|
92
|
+
rubocop-rspec (~> 2.19)
|
|
93
|
+
standard (~> 0.0)
|
|
94
|
+
yard (~> 0.9)
|
|
95
|
+
|
|
96
|
+
BUNDLED WITH
|
|
97
|
+
2.3.17
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Eugene Howe
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# OpenFeature::SDK::Contrib
|
|
2
|
+
|
|
3
|
+
This gem describes a provider for OpenFeature using the following:
|
|
4
|
+
|
|
5
|
+
A feature flag format of:
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
[
|
|
9
|
+
{ "name" => "example_boolean", "kind" => "boolean", "value" => true, "enabled" => true },
|
|
10
|
+
{ "name" => "example_invalid_boolean", "kind" => "boolean", "value" => "a string", "enabled" => true },
|
|
11
|
+
{ "name" => "example_disabled_boolean", "kind" => "boolean", "value" => true, "enabled" => false },
|
|
12
|
+
{ "name" => "example_named_string",
|
|
13
|
+
"kind" => "string",
|
|
14
|
+
"value" => "medium",
|
|
15
|
+
"enabled" => true },
|
|
16
|
+
{ "name" => "example_invalid_named_string",
|
|
17
|
+
"kind" => "string",
|
|
18
|
+
"value" => true,
|
|
19
|
+
"enabled" => true },
|
|
20
|
+
{ "name" => "example_disabled_named_string",
|
|
21
|
+
"kind" => "string",
|
|
22
|
+
"value" => "medium",
|
|
23
|
+
"enabled" => false },
|
|
24
|
+
{ "name" => "example_named_number",
|
|
25
|
+
"kind" => "number",
|
|
26
|
+
"variants" => { "small" => 8, "medium" => 128, "large" => 2048 },
|
|
27
|
+
"value" => "medium",
|
|
28
|
+
"enabled" => true },
|
|
29
|
+
{ "name" => "example_invalid_named_number",
|
|
30
|
+
"kind" => "number",
|
|
31
|
+
"variants" => { "small" => "a string", "medium" => "a string", "large" => "a string" },
|
|
32
|
+
"value" => "medium",
|
|
33
|
+
"enabled" => true },
|
|
34
|
+
{ "name" => "example_disabled_named_number",
|
|
35
|
+
"kind" => "number",
|
|
36
|
+
"variants" => { "small" => 8, "medium" => 128, "large" => 2048 },
|
|
37
|
+
"value" => "medium",
|
|
38
|
+
"enabled" => false },
|
|
39
|
+
{ "name" => "example_named_float",
|
|
40
|
+
"kind" => "float",
|
|
41
|
+
"variants" => { "pi" => 3.141592653589793, "e" => 2.718281828459045, "phi" => 1.618033988749894 },
|
|
42
|
+
"value" => "e",
|
|
43
|
+
"enabled" => true },
|
|
44
|
+
{ "name" => "example_invalid_named_float",
|
|
45
|
+
"kind" => "float",
|
|
46
|
+
"variants" => { "pi" => "a string", "e" => "a string", "phi" => "a string" },
|
|
47
|
+
"value" => "e",
|
|
48
|
+
"enabled" => true },
|
|
49
|
+
{ "name" => "example_disabled_named_float",
|
|
50
|
+
"kind" => "float",
|
|
51
|
+
"variants" => { "pi" => 3.141592653589793, "e" => 2.718281828459045, "phi" => 1.618033988749894 },
|
|
52
|
+
"value" => "e",
|
|
53
|
+
"enabled" => false }
|
|
54
|
+
]
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
This can be read from a file using the `OpenFeature::SDK::Contrib::FileProvider` class or from a URL using the `UrlProvider` class.
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
62
|
+
|
|
63
|
+
$ bundle add openfeature-ruby-sdk-contrib
|
|
64
|
+
|
|
65
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
66
|
+
|
|
67
|
+
$ gem install openfeature-ruby-sdk-contrib
|
|
68
|
+
|
|
69
|
+
## Usage
|
|
70
|
+
|
|
71
|
+
TODO: Write usage instructions here
|
|
72
|
+
|
|
73
|
+
## Development
|
|
74
|
+
|
|
75
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
76
|
+
|
|
77
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
78
|
+
|
|
79
|
+
## Contributing
|
|
80
|
+
|
|
81
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/eugene@xtreme-computers.net/openfeature-ruby-sdk-contrib.
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
module OpenFeature
|
|
2
|
+
module SDK
|
|
3
|
+
module Contrib
|
|
4
|
+
module Providers
|
|
5
|
+
module Common
|
|
6
|
+
# TODO: Should figure out how to use this...
|
|
7
|
+
ResolutionDetails = Struct.new(:value, :reason, :variant, :error_code, :error_message)
|
|
8
|
+
|
|
9
|
+
# @return [String]
|
|
10
|
+
attr_reader :source
|
|
11
|
+
|
|
12
|
+
# @return [Metadata]
|
|
13
|
+
attr_reader :metadata
|
|
14
|
+
|
|
15
|
+
# @return [Symbol]
|
|
16
|
+
attr_reader :format
|
|
17
|
+
|
|
18
|
+
# @return [Array<String>]
|
|
19
|
+
attr_reader :deep_keys
|
|
20
|
+
|
|
21
|
+
# @return [Integer]
|
|
22
|
+
attr_accessor :cache_duration
|
|
23
|
+
|
|
24
|
+
# @return [#call<String>]
|
|
25
|
+
attr_reader :custom_parser
|
|
26
|
+
|
|
27
|
+
# Initialize the provider
|
|
28
|
+
#
|
|
29
|
+
# @param source [String] a path to the file, will be evaluated with expand_path
|
|
30
|
+
# @param file_format [:json, :yaml, :custom] format of the file. Can be one of [:yaml, :json]
|
|
31
|
+
# @param deep_keys [Array<String>] heirarchy of keys to traverse in the parsed config to get to your feature
|
|
32
|
+
# flags Array. Defaults to <tt>[]</tt> which will evaluate to the root of the file
|
|
33
|
+
# @param cache_duration [Integer, Float::INFINITY] how long (in seconds) to cache the file contents before reading the file from disk again.
|
|
34
|
+
# If Float::INFINITY is passed, the file will not be reread.
|
|
35
|
+
# @param custom_parser [#call<String>] If your file is not JSON or YAML you can pass a custom parser as a lambda here which will be used to parse the file instead.
|
|
36
|
+
# Even if your file is YAML or JSON you can pass this option if you opt to use a parser other than <tt>YAML.load</tt> or <tt>JSON.parse</tt>.
|
|
37
|
+
# The raw file contents will be passed to this Proc.
|
|
38
|
+
def initialize(source:, format: :yaml, deep_keys: [], cache_duration: Float::INFINITY, custom_parser: nil)
|
|
39
|
+
@source = source
|
|
40
|
+
@format = format
|
|
41
|
+
@deep_keys = deep_keys
|
|
42
|
+
@cache_duration = cache_duration
|
|
43
|
+
@metadata = Metadata.new(name: self.class::NAME).freeze
|
|
44
|
+
|
|
45
|
+
if format == :yaml && !custom_parser
|
|
46
|
+
require "yaml"
|
|
47
|
+
elsif format == :json && !custom_parser
|
|
48
|
+
require "json"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Returns a boolean value for the key specified
|
|
53
|
+
#
|
|
54
|
+
# @param flag_key [String] flag key to search for
|
|
55
|
+
# @param default_value [Boolean] optional default value if one is not found in the file
|
|
56
|
+
#
|
|
57
|
+
# @return [Boolean, NilClass]
|
|
58
|
+
def fetch_boolean_value(flag_key:, default_value: nil, evaluation_context: nil)
|
|
59
|
+
source_value = read_value_with_cache(flag_key: flag_key, type: "boolean")
|
|
60
|
+
|
|
61
|
+
assert_type(value: source_value, default_value: default_value, return_types: [TrueClass, FalseClass])
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Returns a String value for the key specified
|
|
65
|
+
#
|
|
66
|
+
# @param flag_key [String] flag key to search for
|
|
67
|
+
# @param default_value [String] optional default value if one is not found in the file
|
|
68
|
+
#
|
|
69
|
+
# @return [String, NilClass]
|
|
70
|
+
def fetch_string_value(flag_key:, default_value: nil, evaluation_context: nil)
|
|
71
|
+
source_value = read_value_with_cache(flag_key: flag_key, type: "string")
|
|
72
|
+
|
|
73
|
+
assert_type(value: source_value, default_value: default_value, return_types: [String])
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Returns an integer value for the key specified
|
|
77
|
+
#
|
|
78
|
+
# @param flag_key [String] flag key to search for
|
|
79
|
+
# @param default_value [Integer] optional default value if one is not found in the file
|
|
80
|
+
#
|
|
81
|
+
# @return [Integer, NilClass]
|
|
82
|
+
def fetch_number_value(flag_key:, default_value: nil, evaluation_context: nil)
|
|
83
|
+
source_value = read_value_with_cache(flag_key: flag_key, type: "number")
|
|
84
|
+
|
|
85
|
+
assert_type(value: source_value, default_value: default_value, return_types: [Integer])
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Returns a Float value for the key specified
|
|
89
|
+
#
|
|
90
|
+
# @param flag_key [String] flag key to search for
|
|
91
|
+
# @param default_value [Float] optional default value if one is not found in the file
|
|
92
|
+
#
|
|
93
|
+
# @return [Float, nil]
|
|
94
|
+
def fetch_float_value(flag_key:, default_value: nil, evaluation_context: nil)
|
|
95
|
+
source_value = read_value_with_cache(flag_key: flag_key, type: "float")
|
|
96
|
+
|
|
97
|
+
assert_type(value: source_value, default_value: default_value, return_types: [Float])
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Returns a hash value for the key specified
|
|
101
|
+
#
|
|
102
|
+
# @param flag_key [String] flag key to search for
|
|
103
|
+
# @param default_value [Hash] optional default value if one is not found in the file
|
|
104
|
+
#
|
|
105
|
+
# @return [Hash, NilClass]
|
|
106
|
+
def fetch_object_value(flag_key:, default_value: nil, evaluation_context: nil)
|
|
107
|
+
source_value = read_value_with_cache(flag_key: flag_key, type: "float")
|
|
108
|
+
|
|
109
|
+
assert_type(value: source_value, default_value: default_value, return_types: [Hash])
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
private
|
|
113
|
+
|
|
114
|
+
# Returns a value for the requested flag_key
|
|
115
|
+
#
|
|
116
|
+
# @param flag_key [String] requested flag key
|
|
117
|
+
# @param type ["boolean", "number", "float", "string"]
|
|
118
|
+
def read_value_with_cache(flag_key:, type:)
|
|
119
|
+
now = Time.now.to_i
|
|
120
|
+
|
|
121
|
+
resolve_keys = lambda do |contents|
|
|
122
|
+
flag_contents = deep_keys.empty? ? contents : contents.dig(*deep_keys)
|
|
123
|
+
|
|
124
|
+
flag_contents.detect { |f| f["kind"] == type && f["name"] == flag_key }
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
return resolve_keys.call(@flag_contents) if @flag_contents && (cache_duration == Float::INFINITY || (@last_cache && @flag_contents && now - @last_cache < cache_duration))
|
|
128
|
+
|
|
129
|
+
@flag_contents = resolve_keys.call(read_and_parse_flags)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def read_and_parse_flags
|
|
133
|
+
raise NotImplmentedError
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def assert_type(value:, default_value:, return_types:)
|
|
137
|
+
actual_value = if value && value["enabled"]
|
|
138
|
+
value
|
|
139
|
+
elsif default_value
|
|
140
|
+
{ "value" => default_value }
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
return actual_value if actual_value.nil?
|
|
144
|
+
|
|
145
|
+
return_types = Array(return_types)
|
|
146
|
+
actual_value = actual_value["variants"] ? actual_value["variants"][actual_value["value"]] : actual_value["value"]
|
|
147
|
+
|
|
148
|
+
raise OpenFeature::SDK::Contrib::InvalidReturnValueError, "Invalid flag value found: #{actual_value} is not in #{return_types.join(', ')}" unless return_types.include?(actual_value.class)
|
|
149
|
+
|
|
150
|
+
actual_value
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require "openfeature/sdk"
|
|
2
|
+
|
|
3
|
+
module OpenFeature
|
|
4
|
+
module SDK
|
|
5
|
+
module Contrib
|
|
6
|
+
module Providers
|
|
7
|
+
# Read feature flags from a file.
|
|
8
|
+
#
|
|
9
|
+
# To use <tt>FileProvider</tt>, it can be set during the configuration of the SDK
|
|
10
|
+
#
|
|
11
|
+
# OpenFeature::SDK.configure do |config|
|
|
12
|
+
# config.provider = OpenFeature::SDK::Contrib::FileProvider.new(file_path: "/path/to/file")
|
|
13
|
+
# end
|
|
14
|
+
#
|
|
15
|
+
# Within the <tt>FileProvider</tt>, the following methods exist
|
|
16
|
+
#
|
|
17
|
+
# * <tt>fetch_boolean_value</tt> - Retrieve feature flag boolean value from the file
|
|
18
|
+
#
|
|
19
|
+
# * <tt>fetch_string_value</tt> - Retrieve feature flag string value from the file
|
|
20
|
+
#
|
|
21
|
+
# * <tt>fetch_number_value</tt> - Retrieve feature flag number value from the file
|
|
22
|
+
#
|
|
23
|
+
# * <tt>fetch_object_value</tt> - Retrieve feature flag object value from the file
|
|
24
|
+
class FileProvider
|
|
25
|
+
include Common
|
|
26
|
+
|
|
27
|
+
NAME = "File Provider".freeze
|
|
28
|
+
|
|
29
|
+
def read_and_parse_flags
|
|
30
|
+
file_contents = File.read(File.expand_path(source))
|
|
31
|
+
|
|
32
|
+
return custom_parser.call(file_contents) if custom_parser
|
|
33
|
+
|
|
34
|
+
if format == :yaml
|
|
35
|
+
YAML.safe_load(file_contents)
|
|
36
|
+
else
|
|
37
|
+
JSON.parse(file_contents)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "contrib/version"
|
|
4
|
+
require_relative "contrib/providers/common"
|
|
5
|
+
require_relative "contrib/providers/file_provider"
|
|
6
|
+
|
|
7
|
+
module OpenFeature
|
|
8
|
+
module SDK
|
|
9
|
+
module Contrib
|
|
10
|
+
InvalidReturnValueError = Class.new(StandardError)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: openfeature-ruby-sdk-contrib
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Eugene Howe
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2023-04-05 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: concurrent-ruby
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 1.2.2
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 1.2.2
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: faraday
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 2.7.4
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 2.7.4
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: openfeature-sdk
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0.1'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0.1'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: pry-byebug
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 3.10.1
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 3.10.1
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rspec
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '3.11'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '3.11'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rubocop
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '1.48'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '1.48'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: rubocop-performance
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '1.15'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '1.15'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: rubocop-rake
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - "~>"
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0.6'
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - "~>"
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '0.6'
|
|
125
|
+
- !ruby/object:Gem::Dependency
|
|
126
|
+
name: rubocop-rspec
|
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
|
128
|
+
requirements:
|
|
129
|
+
- - "~>"
|
|
130
|
+
- !ruby/object:Gem::Version
|
|
131
|
+
version: '2.19'
|
|
132
|
+
type: :development
|
|
133
|
+
prerelease: false
|
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
135
|
+
requirements:
|
|
136
|
+
- - "~>"
|
|
137
|
+
- !ruby/object:Gem::Version
|
|
138
|
+
version: '2.19'
|
|
139
|
+
- !ruby/object:Gem::Dependency
|
|
140
|
+
name: standard
|
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
|
142
|
+
requirements:
|
|
143
|
+
- - "~>"
|
|
144
|
+
- !ruby/object:Gem::Version
|
|
145
|
+
version: '0.0'
|
|
146
|
+
type: :development
|
|
147
|
+
prerelease: false
|
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
149
|
+
requirements:
|
|
150
|
+
- - "~>"
|
|
151
|
+
- !ruby/object:Gem::Version
|
|
152
|
+
version: '0.0'
|
|
153
|
+
- !ruby/object:Gem::Dependency
|
|
154
|
+
name: yard
|
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
|
156
|
+
requirements:
|
|
157
|
+
- - "~>"
|
|
158
|
+
- !ruby/object:Gem::Version
|
|
159
|
+
version: '0.9'
|
|
160
|
+
type: :development
|
|
161
|
+
prerelease: false
|
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
163
|
+
requirements:
|
|
164
|
+
- - "~>"
|
|
165
|
+
- !ruby/object:Gem::Version
|
|
166
|
+
version: '0.9'
|
|
167
|
+
description:
|
|
168
|
+
email:
|
|
169
|
+
- eugene.howe@protonmail.com
|
|
170
|
+
executables: []
|
|
171
|
+
extensions: []
|
|
172
|
+
extra_rdoc_files: []
|
|
173
|
+
files:
|
|
174
|
+
- ".rspec"
|
|
175
|
+
- ".rubocop.yml"
|
|
176
|
+
- Gemfile
|
|
177
|
+
- Gemfile.lock
|
|
178
|
+
- LICENSE.txt
|
|
179
|
+
- README.md
|
|
180
|
+
- Rakefile
|
|
181
|
+
- lib/open_feature/sdk/contrib.rb
|
|
182
|
+
- lib/open_feature/sdk/contrib/providers/common.rb
|
|
183
|
+
- lib/open_feature/sdk/contrib/providers/file_provider.rb
|
|
184
|
+
- lib/open_feature/sdk/contrib/version.rb
|
|
185
|
+
homepage: https://github.com/ehowe/openfeature-ruby-sdk-contrib
|
|
186
|
+
licenses:
|
|
187
|
+
- MIT
|
|
188
|
+
metadata:
|
|
189
|
+
homepage_uri: https://github.com/ehowe/openfeature-ruby-sdk-contrib
|
|
190
|
+
source_code_uri: https://github.com/ehowe/openfeature-ruby-sdk-contrib
|
|
191
|
+
rubygems_mfa_required: 'true'
|
|
192
|
+
post_install_message:
|
|
193
|
+
rdoc_options: []
|
|
194
|
+
require_paths:
|
|
195
|
+
- lib
|
|
196
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
197
|
+
requirements:
|
|
198
|
+
- - ">="
|
|
199
|
+
- !ruby/object:Gem::Version
|
|
200
|
+
version: '3.0'
|
|
201
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
|
+
requirements:
|
|
203
|
+
- - ">="
|
|
204
|
+
- !ruby/object:Gem::Version
|
|
205
|
+
version: '0'
|
|
206
|
+
requirements: []
|
|
207
|
+
rubygems_version: 3.2.33
|
|
208
|
+
signing_key:
|
|
209
|
+
specification_version: 4
|
|
210
|
+
summary: Providers and Hooks for the OpenFeature Ruby SDK
|
|
211
|
+
test_files: []
|