openfeature-ruby-sdk-contrib 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 320d3f69c1bcab1d432d639303486551c4d1fc92afa77be8b9ffc9843a4f48fd
4
- data.tar.gz: 92b8a57f051e57788ce6082c66fd3b222ec58e1eb7ea42b7fd0f664d9e428f6f
3
+ metadata.gz: 2adc3ef477b7826d65812fed65732d1bd591226af99106fb96cb0c3fa14bd827
4
+ data.tar.gz: c98c2ff2f6930a7831041dd4a5b01de77c30d33e5dfbb510cce05bad1ab9a731
5
5
  SHA512:
6
- metadata.gz: b7bcdc2163db7f58f0741dc6c172769ef11500647676908e200e77edb52bdb48f2be34dfd5f8374388d1b519f24b0febfbe066893b75b75846bc808ffd6d8b71
7
- data.tar.gz: 270aedda5e88c6402c5d5a49a0342d824c8848f71cae05b003c847942abf496d916fe02ca4807a1b87bf28a051568abc08b81af32b1715b69c2878e80664e779
6
+ metadata.gz: 2903c569b112dd6c4484513bddea2356694f5572ceef0202065420d511af3c903bb980f9fbdf65ced5cc6c069c112ee41623a8dbacf84df2b64eba55f0a03edf
7
+ data.tar.gz: ed7d607c742ffefd5a0b4eca6c4c6fe5dc31aaa8841de3588b1e9bdcf000a6c4b3d12a86882ac7d40bfcb4987b0dda693dadeedde53d1392b038763faab6a9a3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openfeature-ruby-sdk-contrib (0.0.1)
4
+ openfeature-ruby-sdk-contrib (0.0.3)
5
5
  concurrent-ruby (~> 1.2.2)
6
6
  faraday (~> 2.7.4)
7
7
  openfeature-sdk (~> 0.1)
@@ -0,0 +1,13 @@
1
+ require "openfeature/sdk/client"
2
+
3
+ module OpenFeature
4
+ module SDK
5
+ module Contrib
6
+ class Client < OpenFeature::SDK::Client
7
+ def all_flags
8
+ @provider.read_all_values_with_cache
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -116,32 +116,35 @@ module OpenFeature
116
116
  assert_type(value: source_value, default_value: default_value, return_types: [Hash])
117
117
  end
118
118
 
119
- private
120
-
121
- # Returns a value for the requested flag_key
122
- #
123
- # @param flag_key [String] requested flag key
124
- # @param type ["boolean", "number", "float", "string"]
125
- def read_value_with_cache(flag_key:, type:)
119
+ def read_all_values_with_cache
126
120
  now = Time.now.to_i
127
121
 
128
122
  read_from_cache = if !@flag_contents
129
123
  false
130
- elsif cache_duration == Float::INFINITY
131
- true
132
124
  elsif !@last_cache
133
125
  false
126
+ elsif cache_duration == Float::INFINITY
127
+ true
134
128
  else
135
129
  now - @last_cache < cache_duration
136
130
  end
137
131
 
138
132
  unless read_from_cache
139
- @last_cache = Time.now.to_i
140
- @flag_contents = read_and_parse_flags unless read_from_cache
133
+ read_and_parse_flags
134
+ @last_cache = Time.now.to_i
141
135
  end
142
136
 
143
- flags = deep_keys.empty? ? @flag_contents : @flag_contents.dig(*deep_keys)
144
- flag = flags.detect { |f| f["kind"] == type && f["name"] == flag_key }
137
+ (deep_keys.empty? ? @flag_contents : @flag_contents.dig(*deep_keys) || [])
138
+ end
139
+
140
+ private
141
+
142
+ # Returns a value for the requested flag_key
143
+ #
144
+ # @param flag_key [String] requested flag key
145
+ # @param type ["boolean", "number", "float", "string"]
146
+ def read_value_with_cache(flag_key:, type:)
147
+ read_all_values_with_cache.detect { |f| f["kind"] == type && f["name"] == flag_key }
145
148
  end
146
149
 
147
150
  def read_and_parse_flags
@@ -151,8 +154,8 @@ module OpenFeature
151
154
  def assert_type(value:, default_value:, return_types:)
152
155
  actual_value = if value && value["enabled"]
153
156
  value
154
- elsif default_value
155
- { "value" => default_value }
157
+ elsif defined?(default_value)
158
+ { "value" => default_value, "enabled" => true }
156
159
  end
157
160
 
158
161
  return ResolutionDetails.new(value: nil) if actual_value.nil?
@@ -27,15 +27,22 @@ module OpenFeature
27
27
  NAME = "File Provider".freeze
28
28
 
29
29
  def read_and_parse_flags
30
- file_contents = File.read(File.expand_path(source))
30
+ file_contents = begin
31
+ File.read(File.expand_path(source))
32
+ rescue Errno::ENOENT
33
+ @flag_contents = {}
34
+ return
35
+ end
31
36
 
32
37
  return custom_parser.call(file_contents) if custom_parser
33
38
 
34
- if format == :yaml
35
- YAML.safe_load(file_contents)
36
- else
37
- JSON.parse(file_contents)
38
- end
39
+ @flag_contents = if format == :yaml
40
+ YAML.safe_load(file_contents)
41
+ else
42
+ JSON.parse(file_contents)
43
+ end
44
+
45
+ @flag_contents
39
46
  end
40
47
  end
41
48
  end
@@ -3,7 +3,7 @@
3
3
  module OpenFeature
4
4
  module SDK
5
5
  module Contrib
6
- VERSION = "0.0.2"
6
+ VERSION = "0.0.4"
7
7
  end
8
8
  end
9
9
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "contrib/client"
3
4
  require_relative "contrib/version"
4
5
  require_relative "contrib/providers/common"
5
6
  require_relative "contrib/providers/file_provider"
@@ -10,4 +11,4 @@ module OpenFeature
10
11
  InvalidReturnValueError = Class.new(StandardError)
11
12
  end
12
13
  end
13
- end
14
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openfeature-ruby-sdk-contrib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugene Howe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-05 00:00:00.000000000 Z
11
+ date: 2023-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -179,6 +179,7 @@ files:
179
179
  - README.md
180
180
  - Rakefile
181
181
  - lib/open_feature/sdk/contrib.rb
182
+ - lib/open_feature/sdk/contrib/client.rb
182
183
  - lib/open_feature/sdk/contrib/providers/common.rb
183
184
  - lib/open_feature/sdk/contrib/providers/file_provider.rb
184
185
  - lib/open_feature/sdk/contrib/version.rb