openfeature-ruby-sdk-contrib 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce92cec4c5146fcee215e7edca3f4daf9757a1cd4fda456176d197c861b0c620
4
- data.tar.gz: bbfd473392d8143ae247ac862a6f6e591bb6e679d6bfad309bfb4ecf78f78976
3
+ metadata.gz: 320d3f69c1bcab1d432d639303486551c4d1fc92afa77be8b9ffc9843a4f48fd
4
+ data.tar.gz: 92b8a57f051e57788ce6082c66fd3b222ec58e1eb7ea42b7fd0f664d9e428f6f
5
5
  SHA512:
6
- metadata.gz: d19265c25e33347ecb64eb29bd7d31384bd739a2e24564d7176feb60d51c34d0d5fef9190964fd67bd7c04672be7afad9926cabc9ad20fdbeb6293a6232f7f28
7
- data.tar.gz: 757c5224f87fc475635c64b44c36fc87a8a183f6c51a225d207a9f437e89d54a15bb0606b72b8946e4753c372ad07d303e9e8a2cbe88d16a06b5c70d66e208c7
6
+ metadata.gz: b7bcdc2163db7f58f0741dc6c172769ef11500647676908e200e77edb52bdb48f2be34dfd5f8374388d1b519f24b0febfbe066893b75b75846bc808ffd6d8b71
7
+ data.tar.gz: 270aedda5e88c6402c5d5a49a0342d824c8848f71cae05b003c847942abf496d916fe02ca4807a1b87bf28a051568abc08b81af32b1715b69c2878e80664e779
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openfeature-ruby-sdk-contrib (0.1.0)
4
+ openfeature-ruby-sdk-contrib (0.0.1)
5
5
  concurrent-ruby (~> 1.2.2)
6
6
  faraday (~> 2.7.4)
7
7
  openfeature-sdk (~> 0.1)
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
- TODO: Write usage instructions here
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/eugene@xtreme-computers.net/openfeature-ruby-sdk-contrib.
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
- # TODO: Should figure out how to use this...
7
- ResolutionDetails = Struct.new(:value, :reason, :variant, :error_code, :error_message)
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
- 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 }
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
- 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)
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 actual_value if actual_value.nil?
158
+ return ResolutionDetails.new(value: nil) if actual_value.nil?
144
159
 
145
- return_types = Array(return_types)
146
- actual_value = actual_value["variants"] ? actual_value["variants"][actual_value["value"]] : actual_value["value"]
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: #{actual_value} is not in #{return_types.join(', ')}" unless return_types.include?(actual_value.class)
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
@@ -3,7 +3,7 @@
3
3
  module OpenFeature
4
4
  module SDK
5
5
  module Contrib
6
- VERSION = "0.0.1"
6
+ VERSION = "0.0.2"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openfeature-ruby-sdk-contrib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugene Howe