openfeature-ruby-sdk-contrib 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +8 -2
- data/lib/open_feature/sdk/contrib/providers/common.rb +29 -14
- data/lib/open_feature/sdk/contrib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 320d3f69c1bcab1d432d639303486551c4d1fc92afa77be8b9ffc9843a4f48fd
|
4
|
+
data.tar.gz: 92b8a57f051e57788ce6082c66fd3b222ec58e1eb7ea42b7fd0f664d9e428f6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7bcdc2163db7f58f0741dc6c172769ef11500647676908e200e77edb52bdb48f2be34dfd5f8374388d1b519f24b0febfbe066893b75b75846bc808ffd6d8b71
|
7
|
+
data.tar.gz: 270aedda5e88c6402c5d5a49a0342d824c8848f71cae05b003c847942abf496d916fe02ca4807a1b87bf28a051568abc08b81af32b1715b69c2878e80664e779
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -68,7 +68,13 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
68
68
|
|
69
69
|
## Usage
|
70
70
|
|
71
|
-
|
71
|
+
```
|
72
|
+
require "open_feature/sdk/contrib"
|
73
|
+
|
74
|
+
OpenFeature::SDK.configure do |config|
|
75
|
+
config.provider = OpenFeature::SDK::Contrib::Providers::FileProvider.new(source: "path/to/file", format: :yaml)
|
76
|
+
end
|
77
|
+
```
|
72
78
|
|
73
79
|
## Development
|
74
80
|
|
@@ -78,7 +84,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
78
84
|
|
79
85
|
## Contributing
|
80
86
|
|
81
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
87
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ehowe/openfeature-ruby-sdk-contrib.
|
82
88
|
|
83
89
|
## License
|
84
90
|
|
@@ -3,8 +3,15 @@ module OpenFeature
|
|
3
3
|
module Contrib
|
4
4
|
module Providers
|
5
5
|
module Common
|
6
|
-
|
7
|
-
|
6
|
+
ResolutionDetails = Struct.new(
|
7
|
+
:enabled,
|
8
|
+
:error_code,
|
9
|
+
:error_message,
|
10
|
+
:reason,
|
11
|
+
:value,
|
12
|
+
:variant,
|
13
|
+
keyword_init: true
|
14
|
+
)
|
8
15
|
|
9
16
|
# @return [String]
|
10
17
|
attr_reader :source
|
@@ -118,15 +125,23 @@ module OpenFeature
|
|
118
125
|
def read_value_with_cache(flag_key:, type:)
|
119
126
|
now = Time.now.to_i
|
120
127
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
128
|
+
read_from_cache = if !@flag_contents
|
129
|
+
false
|
130
|
+
elsif cache_duration == Float::INFINITY
|
131
|
+
true
|
132
|
+
elsif !@last_cache
|
133
|
+
false
|
134
|
+
else
|
135
|
+
now - @last_cache < cache_duration
|
136
|
+
end
|
137
|
+
|
138
|
+
unless read_from_cache
|
139
|
+
@last_cache = Time.now.to_i
|
140
|
+
@flag_contents = read_and_parse_flags unless read_from_cache
|
125
141
|
end
|
126
142
|
|
127
|
-
|
128
|
-
|
129
|
-
@flag_contents = resolve_keys.call(read_and_parse_flags)
|
143
|
+
flags = deep_keys.empty? ? @flag_contents : @flag_contents.dig(*deep_keys)
|
144
|
+
flag = flags.detect { |f| f["kind"] == type && f["name"] == flag_key }
|
130
145
|
end
|
131
146
|
|
132
147
|
def read_and_parse_flags
|
@@ -140,14 +155,14 @@ module OpenFeature
|
|
140
155
|
{ "value" => default_value }
|
141
156
|
end
|
142
157
|
|
143
|
-
return
|
158
|
+
return ResolutionDetails.new(value: nil) if actual_value.nil?
|
144
159
|
|
145
|
-
return_types
|
146
|
-
|
160
|
+
return_types = Array(return_types)
|
161
|
+
variant_value = actual_value["variants"] ? actual_value["variants"][actual_value["value"]] : actual_value["value"]
|
147
162
|
|
148
|
-
raise OpenFeature::SDK::Contrib::InvalidReturnValueError, "Invalid flag value found: #{
|
163
|
+
raise OpenFeature::SDK::Contrib::InvalidReturnValueError, "Invalid flag value found: #{variant_value} is not in #{return_types.join(', ')}" unless return_types.include?(variant_value.class)
|
149
164
|
|
150
|
-
actual_value
|
165
|
+
ResolutionDetails.new(value: variant_value, enabled: actual_value["enabled"], variant: actual_value["variant"])
|
151
166
|
end
|
152
167
|
end
|
153
168
|
end
|