featurehub-sdk 1.0.0 → 1.1.0

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: 8a918d4c2cd828f070ede69b41bccaef489154f189bc93b497256f3589abec7f
4
- data.tar.gz: 320522f90925794e6a12df0e3a034ddb46b81a69445d201447bc1bd51743d4e6
3
+ metadata.gz: c4621f1ab8e515ab8eec3b701bf3928d1eabfafbe21a955175729dfeb39ed31b
4
+ data.tar.gz: 3e57a7dc1e0e525e6da0dca8848d42fd09eea437a378162160b5e529422fa12c
5
5
  SHA512:
6
- metadata.gz: 5ab24c0101cf91b2a0be85a92e5665d21397a7733be165c2c718208887b1060e29c621e12595ff4b2bbbf4f502fd40a6f1da89b62e147d77f2e9a4c9bd981f15
7
- data.tar.gz: 00ee27a652e9c85cabed5e331c18d4bfb68ee32e625e513f330f8534a89cc191c63f1320ce466d80807cf7a0d7518950da78b005e3c759d0e76791a060757607
6
+ metadata.gz: 95899cd71c1c70756cddc97821c30173ef5381c0ba384d58e9be0b6c57664b59be85e4f748d55723677b84dfdda276df48526a8bb603165da911af1fc0344305
7
+ data.tar.gz: 8840b4aa7359fa5bbbc3247bac92df4fc96915c788737d08e3d4a0ccd92542536e05b527411875f17b4a5b94b7614f033303eaba93d349a88be200e010f8ccef
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## [1.1.0] - 2022-10-12
2
+
3
+ - Adds support for array values in flag evaluation contexts via [this PR](https://github.com/featurehub-io/featurehub-ruby-sdk/pull/12)
1
4
  ## [1.0.0] - 2022-06-06
2
5
 
3
6
  - Initial release, feature complete
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- featurehub-sdk (1.0.0)
4
+ featurehub-sdk (1.1.0)
5
5
  concurrent-ruby (~> 1.1.10)
6
6
  faraday (~> 2.3)
7
7
  ld-eventsource (~> 2.2.0)
@@ -73,7 +73,7 @@ module FeatureHub
73
73
  end
74
74
 
75
75
  def get_attr(key, default_val = nil)
76
- (@attributes[key.to_sym] || [default_val])[0]
76
+ (@attributes[key.to_sym] || [default_val]).compact
77
77
  end
78
78
 
79
79
  def default_percentage_key
@@ -67,26 +67,30 @@ module FeatureHub
67
67
 
68
68
  def match_attribute(context, rs_attr)
69
69
  rs_attr.attributes.each do |attr|
70
- supplied_value = context.get_attr(attr.field_name)
71
- if supplied_value.nil? && attr.field_name.downcase == "now"
70
+ supplied_values = context.get_attr(attr.field_name)
71
+ if supplied_values.empty? && attr.field_name.downcase == "now"
72
72
  case attr.field_type
73
73
  when "DATE"
74
- supplied_value = Time.new.utc.iso8601[0..9]
74
+ supplied_values = [Time.new.utc.iso8601[0..9]]
75
75
  when "DATETIME"
76
- supplied_value = Time.new.utc.iso8601
76
+ supplied_values = [Time.new.utc.iso8601]
77
77
  end
78
78
  end
79
79
 
80
- if attr.values.nil? && supplied_value.nil?
80
+ if attr.values.nil? && supplied_values.empty?
81
81
  return false unless attr.conditional.equals?
82
82
 
83
83
  next
84
84
  end
85
85
 
86
- return false if attr.values.nil? || supplied_value.nil?
86
+ return false if attr.values.nil? || supplied_values.empty?
87
87
 
88
88
  # this attribute has to match or we failed
89
- return false unless @matcher_repository.find_matcher(attr).match(supplied_value, attr)
89
+ match = supplied_values.any? do |supplied_value|
90
+ @matcher_repository.find_matcher(attr).match(supplied_value, attr)
91
+ end
92
+
93
+ return false unless match
90
94
  end
91
95
 
92
96
  true
@@ -3,7 +3,7 @@
3
3
  module FeatureHub
4
4
  # already documented elsewhere
5
5
  module Sdk
6
- VERSION = "1.0.0"
6
+ VERSION = "1.1.0"
7
7
 
8
8
  def default_logger
9
9
  log = ::Logger.new($stdout)
@@ -1,6 +1,7 @@
1
1
  module FeatureHub
2
2
  module Sdk
3
3
  VERSION: String
4
+
4
5
  # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
6
  #
6
7
 
@@ -11,13 +12,17 @@ module FeatureHub
11
12
  feature_state: Hash[untyped, untyped]?, parent_state: FeatureState?, ctx: ClientContext?) -> void
12
13
 
13
14
  def locked?: -> bool
15
+
14
16
  def exists?: (top_feature: FeatureState?) -> bool
17
+
15
18
  def id: -> String?
19
+
16
20
  def feature_type: -> String?
17
21
 
18
22
  def with_context: (ctx: ClientContext) -> FeatureState
19
23
 
20
24
  def update_feature_state: (feature_state: Hash[untyped, untyped]) -> void
25
+
21
26
  # this is the feature state of the top level, it always walks up
22
27
  def feature_state: () -> Hash[untyped, untyped]
23
28
 
@@ -57,19 +62,20 @@ module FeatureHub
57
62
  attr_reader matched: bool
58
63
  attr_reader value: [bool? | String? | Float?]
59
64
 
60
- def initialize:(matched: bool, value: [bool? | String? | Float?]) -> void
65
+ def initialize: (matched: bool, value: [bool? | String? | Float?]) -> void
61
66
  end
62
67
 
63
68
  class InterceptorValue
64
- def initialize: (val: [bool? | String? | Float? ]) -> void
65
- def cast:(feature_type: String?) -> [bool? | String? | Float? ]
69
+ def initialize: (val: [bool? | String? | Float?]) -> void
70
+
71
+ def cast: (feature_type: String?) -> [bool? | String? | Float?]
66
72
  end
67
73
 
68
74
  class ValueInterceptor
69
75
  def intercepted_value: (feature_key: Symbol) -> InterceptorValue?
70
76
  end
71
77
 
72
- class EnvironmentInterceptor < ValueInterceptor
78
+ class EnvironmentInterceptor < ValueInterceptor
73
79
  end
74
80
 
75
81
  class PercentageCalculator
@@ -78,17 +84,25 @@ module FeatureHub
78
84
 
79
85
  class ApplyFeatures
80
86
  def initialize: (percent_calculator: PercentageCalculator?, matcher_repository: MatcherRepository?) -> void
87
+
81
88
  def apply: (strategies: Array[RolloutStrategy], key: String, feature_value_id: String, context: ClientContext) -> Applied
89
+
82
90
  def match_attribute: (context: ClientContext, rs: RolloutStrategyAttribute) -> bool
91
+
83
92
  def self.determine_percentage_key: (context: ClientContext, rsi: RolloutStrategy) -> String?
84
93
  end
85
94
 
86
95
  class InternalFeatureRepository
87
96
  def feature: (key: String) -> FeatureState?
97
+
88
98
  def find_interceptor: (feature_value: String) -> InterceptorValue?
99
+
89
100
  def ready?: -> bool
101
+
90
102
  def not_ready!: -> void
103
+
91
104
  def apply: (strategies: Array[RolloutStrategy], key: String, feature_id: String, context: ClientContext) -> Applied
105
+
92
106
  def notify: (status: String, data: Hash[untyped, untyped]) -> void
93
107
  end
94
108
 
@@ -96,15 +110,20 @@ module FeatureHub
96
110
  @features: Hash[String, FeatureState]
97
111
  @ready: bool
98
112
 
99
- def initialize: (apply_features: nil | ApplyFeatures ) -> void
100
- def apply:(strategies: Array[RolloutStrategy], key: String, feature_id: String, context: ClientContext) -> Applied
113
+ def initialize: (apply_features: nil | ApplyFeatures) -> void
114
+
115
+ def apply: (strategies: Array[RolloutStrategy], key: String, feature_id: String, context: ClientContext) -> Applied
101
116
 
102
117
  def notify: (status: String, data: Hash[untyped, untyped]) -> void
118
+
103
119
  def feature: (key: String) -> FeatureState
120
+
104
121
  def register_interceptor: (interceptor: ValueInterceptor) -> void
105
122
 
106
123
  def find_interceptor: (feature_value: String) -> InterceptorValue?
124
+
107
125
  def ready?: -> bool
126
+
108
127
  def not_ready!: -> void
109
128
 
110
129
  def extract_feature_state: -> Array[Hash[untyped, untyped]]
@@ -114,37 +133,61 @@ module FeatureHub
114
133
  attr_reader repo: InternalFeatureRepository
115
134
 
116
135
  def initialize: (repository: InternalFeatureRepository) -> void
136
+
117
137
  def user_key: (value: String) -> ClientContext
138
+
118
139
  def session_key: (value: String) -> ClientContext
140
+
119
141
  def version: (value: String) -> ClientContext
120
- def country: (value: Symbol ) -> ClientContext
121
- def platform: (value: Symbol ) -> ClientContext
122
- def device: (value: Symbol ) -> ClientContext
123
- def attribute_value: (key: String, values: Array[String] ) -> ClientContext
142
+
143
+ def country: (value: Symbol) -> ClientContext
144
+
145
+ def platform: (value: Symbol) -> ClientContext
146
+
147
+ def device: (value: Symbol) -> ClientContext
148
+
149
+ def attribute_value: (key: String, values: Array[String]) -> ClientContext
150
+
124
151
  def clear: -> ClientContext
125
- def get_attr: (key: String, default_val: String?) -> String?
152
+
153
+ def get_attr: (key: String, default_val: String?) -> Array[String]
154
+
126
155
  def default_percentage_key: -> String?
156
+
127
157
  def enabled: (key: String) -> bool?
128
158
 
129
159
  def feature: (key: String) -> FeatureState
160
+
130
161
  def set?: (key: String) -> bool?
162
+
131
163
  def number: (key: String) -> Float?
164
+
132
165
  def string: (key: String) -> String?
166
+
133
167
  def json: (key: String) -> Hash[untyped, untyped]?
168
+
134
169
  def raw_json: (key: String) -> String?
170
+
135
171
  def flag: (key: String) -> bool?
172
+
136
173
  def boolean: (key: String) -> bool?
174
+
137
175
  def exists?: (key: String) -> bool
138
176
 
139
177
  def build: -> ClientContext
178
+
140
179
  def build_sync: -> ClientContext
180
+
141
181
  def close: -> ClientContext
142
182
  end
143
183
 
144
184
  class EdgeService
145
185
  def initialize: (repository: InternalFeatureRepository, api_keys: Array[String], edge_url: String) -> void
186
+
146
187
  def poll: -> void
188
+
147
189
  def context_change: (new_header: String?) -> void
190
+
148
191
  def close: -> void
149
192
  end
150
193
 
@@ -189,15 +232,25 @@ module FeatureHub
189
232
 
190
233
  class RolloutStrategyCondition
191
234
  def equals?: -> bool
235
+
192
236
  def ends_with?: -> bool
237
+
193
238
  def starts_with?: -> bool
239
+
194
240
  def greater?: -> bool
241
+
195
242
  def greater_equals?: -> bool
243
+
196
244
  def less?: -> bool
245
+
197
246
  def less_equals?: -> bool
247
+
198
248
  def not_equals?: -> bool
249
+
199
250
  def includes?: -> bool
251
+
200
252
  def excludes?: -> bool
253
+
201
254
  def regex?: -> bool
202
255
  end
203
256
 
@@ -209,6 +262,7 @@ module FeatureHub
209
262
  attr_reader field_type: String
210
263
 
211
264
  def float_values: -> Array[Float]
265
+
212
266
  def str_values: -> Array[String]
213
267
  end
214
268
 
@@ -221,15 +275,16 @@ module FeatureHub
221
275
  attr_reader value: [bool? | String? | Float?]
222
276
 
223
277
  def percentage_attributes?: -> bool
278
+
224
279
  def attributes?: -> bool
225
280
  end
226
281
 
227
282
  class StrategyMatcher
228
- def match: (supplied_value: String, attr: RolloutStrategyAttribute ) -> bool
283
+ def match: (supplied_value: String, attr: RolloutStrategyAttribute) -> bool
229
284
  end
230
285
 
231
286
  class BooleanMatcher < StrategyMatcher
232
- def match: (supplied_value: String, attr: RolloutStrategyAttribute ) -> bool
287
+ def match: (supplied_value: String, attr: RolloutStrategyAttribute) -> bool
233
288
  end
234
289
 
235
290
  class StringMatcher < StrategyMatcher
@@ -250,7 +305,6 @@ module FeatureHub
250
305
 
251
306
  class MatcherRegistry < MatcherRepository
252
307
  end
253
- end
308
+ end
254
309
 
255
310
  end
256
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: featurehub-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Vowles
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-06-16 00:00:00.000000000 Z
12
+ date: 2022-10-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: concurrent-ruby
@@ -90,6 +90,7 @@ extra_rdoc_files: []
90
90
  files:
91
91
  - ".rspec"
92
92
  - ".rubocop.yml"
93
+ - ".ruby-version"
93
94
  - CHANGELOG.md
94
95
  - CODE_OF_CONDUCT.md
95
96
  - Gemfile