prefab-cloud-ruby 0.23.8 → 0.24.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -8
- data/VERSION +1 -1
- data/lib/prefab/client.rb +55 -21
- data/lib/prefab/config_client.rb +13 -25
- data/lib/prefab/config_resolver.rb +28 -28
- data/lib/prefab/config_value_unwrapper.rb +8 -5
- data/lib/prefab/context.rb +119 -0
- data/lib/prefab/criteria_evaluator.rb +23 -17
- data/lib/prefab/feature_flag_client.rb +7 -7
- data/lib/prefab/local_config_parser.rb +2 -17
- data/lib/prefab/logger_client.rb +3 -6
- data/lib/prefab/resolved_config_presenter.rb +84 -0
- data/lib/prefab/weighted_value_resolver.rb +4 -4
- data/lib/prefab-cloud-ruby.rb +6 -0
- data/prefab-cloud-ruby.gemspec +6 -3
- data/test/.prefab.unit_tests.config.yaml +3 -2
- data/test/integration_test.rb +4 -8
- data/test/test_client.rb +28 -27
- data/test/test_config_resolver.rb +106 -54
- data/test/test_config_value_unwrapper.rb +15 -15
- data/test/test_context.rb +158 -0
- data/test/test_criteria_evaluator.rb +93 -78
- data/test/test_feature_flag_client.rb +14 -20
- data/test/test_helper.rb +1 -1
- data/test/test_integration.rb +30 -14
- data/test/test_local_config_parser.rb +6 -8
- data/test/test_log_path_collector.rb +4 -7
- data/test/test_logger.rb +12 -12
- metadata +5 -2
@@ -34,14 +34,13 @@ class TestLocalConfigParser < Minitest::Test
|
|
34
34
|
assert_equal 1, config.rows[0].values.size
|
35
35
|
|
36
36
|
value_row = config.rows[0].values[0]
|
37
|
-
assert_equal Prefab::WeightedValues, value_row.value.weighted_values.class
|
38
37
|
assert_equal 'all-features', Prefab::ConfigValueUnwrapper.unwrap(value_row.value, key, {})
|
39
38
|
end
|
40
39
|
|
41
|
-
def
|
42
|
-
key = :
|
43
|
-
value = stringify_keys({
|
44
|
-
criterion: { operator: '
|
40
|
+
def test_flag_in_user_key
|
41
|
+
key = :flag_in_user_key
|
42
|
+
value = stringify_keys({ 'feature_flag': 'true', value: true,
|
43
|
+
criterion: { operator: 'PROP_IS_ONE_OF', property: 'user.key', values: %w[abc123 xyz987] } })
|
45
44
|
parsed = Prefab::LocalConfigParser.parse(key, value, {}, FILE_NAME)[key]
|
46
45
|
config = parsed[:config]
|
47
46
|
|
@@ -54,11 +53,10 @@ class TestLocalConfigParser < Minitest::Test
|
|
54
53
|
assert_equal 1, config.rows[0].values[0].criteria.size
|
55
54
|
|
56
55
|
value_row = config.rows[0].values[0]
|
57
|
-
assert_equal Prefab::WeightedValues, value_row.value.weighted_values.class
|
58
56
|
assert_equal true, Prefab::ConfigValueUnwrapper.unwrap(value_row.value, key, {})
|
59
57
|
|
60
|
-
assert_equal
|
61
|
-
assert_equal :
|
58
|
+
assert_equal 'user.key', value_row.criteria[0].property_name
|
59
|
+
assert_equal :PROP_IS_ONE_OF, value_row.criteria[0].operator
|
62
60
|
assert_equal %w[abc123 xyz987], value_row.criteria[0].value_to_match.string_list.values
|
63
61
|
end
|
64
62
|
|
@@ -49,13 +49,10 @@ class TestLogPathCollector < Minitest::Test
|
|
49
49
|
private
|
50
50
|
|
51
51
|
def new_client(overrides = {})
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
api_key: '123-development-yourapikey-SDK'
|
52
|
+
super(**{
|
53
|
+
prefab_datasources: Prefab::Options::DATASOURCES::ALL,
|
54
|
+
api_key: '123-development-yourapikey-SDK',
|
55
|
+
collect_sync_interval: 1000 # we'll trigger sync manually in our test
|
57
56
|
}.merge(overrides))
|
58
|
-
|
59
|
-
Prefab::Client.new(options)
|
60
57
|
end
|
61
58
|
end
|
data/test/test_logger.rb
CHANGED
@@ -192,7 +192,7 @@ class TestLogger < Minitest::Test
|
|
192
192
|
Prefab::Criterion.new(
|
193
193
|
operator: Prefab::Criterion::CriterionOperator::PROP_IS_ONE_OF,
|
194
194
|
value_to_match: string_list(['hotmail.com', 'gmail.com']),
|
195
|
-
property_name: 'email_suffix'
|
195
|
+
property_name: 'user.email_suffix'
|
196
196
|
)
|
197
197
|
],
|
198
198
|
value: Prefab::ConfigValue.new(log_level: WRONG_ENV_VALUE)
|
@@ -209,7 +209,7 @@ class TestLogger < Minitest::Test
|
|
209
209
|
Prefab::Criterion.new(
|
210
210
|
operator: Prefab::Criterion::CriterionOperator::PROP_IS_ONE_OF,
|
211
211
|
value_to_match: string_list(['hotmail.com', 'gmail.com']),
|
212
|
-
property_name: 'email_suffix'
|
212
|
+
property_name: 'user.email_suffix'
|
213
213
|
)
|
214
214
|
],
|
215
215
|
value: Prefab::ConfigValue.new(log_level: DESIRED_VALUE)
|
@@ -228,7 +228,7 @@ class TestLogger < Minitest::Test
|
|
228
228
|
inject_project_env_id(prefab, PROJECT_ENV_ID)
|
229
229
|
|
230
230
|
# without any context, the level should be the default for the env (info)
|
231
|
-
prefab.
|
231
|
+
prefab.with_context({}) do
|
232
232
|
prefab.log.debug 'Test debug'
|
233
233
|
refute_logged io, 'Test debug'
|
234
234
|
|
@@ -242,7 +242,7 @@ class TestLogger < Minitest::Test
|
|
242
242
|
reset_io(io)
|
243
243
|
|
244
244
|
# with the wrong context, the level should be the default for the env (info)
|
245
|
-
prefab.
|
245
|
+
prefab.with_context(user: { email_suffix: 'yahoo.com' }) do
|
246
246
|
prefab.log.debug 'Test debug'
|
247
247
|
refute_logged io, 'Test debug'
|
248
248
|
|
@@ -256,7 +256,7 @@ class TestLogger < Minitest::Test
|
|
256
256
|
reset_io(io)
|
257
257
|
|
258
258
|
# with the correct context, the level should be the desired value (debug)
|
259
|
-
prefab.
|
259
|
+
prefab.with_context(user: { email_suffix: 'hotmail.com' }) do
|
260
260
|
prefab.log.debug 'Test debug'
|
261
261
|
assert_logged io, 'DEBUG', "#{prefix}.test.test_logger.test_logging_with_criteria_on_top_level_key", 'Test debug'
|
262
262
|
|
@@ -302,7 +302,7 @@ class TestLogger < Minitest::Test
|
|
302
302
|
Prefab::Criterion.new(
|
303
303
|
operator: Prefab::Criterion::CriterionOperator::PROP_IS_ONE_OF,
|
304
304
|
value_to_match: string_list(['hotmail.com', 'gmail.com']),
|
305
|
-
property_name: 'email_suffix'
|
305
|
+
property_name: 'user.email_suffix'
|
306
306
|
)
|
307
307
|
],
|
308
308
|
value: Prefab::ConfigValue.new(log_level: DESIRED_VALUE)
|
@@ -311,9 +311,9 @@ class TestLogger < Minitest::Test
|
|
311
311
|
Prefab::ConditionalValue.new(
|
312
312
|
criteria: [
|
313
313
|
Prefab::Criterion.new(
|
314
|
-
operator: Prefab::Criterion::CriterionOperator::
|
314
|
+
operator: Prefab::Criterion::CriterionOperator::PROP_IS_ONE_OF,
|
315
315
|
value_to_match: string_list(%w[user:4567]),
|
316
|
-
property_name:
|
316
|
+
property_name: 'user.tracking_id'
|
317
317
|
)
|
318
318
|
],
|
319
319
|
value: Prefab::ConfigValue.new(log_level: DESIRED_VALUE)
|
@@ -333,7 +333,7 @@ class TestLogger < Minitest::Test
|
|
333
333
|
inject_project_env_id(prefab, PROJECT_ENV_ID)
|
334
334
|
|
335
335
|
# without any context, the level should be the default for the env (info)
|
336
|
-
prefab.
|
336
|
+
prefab.with_context({}) do
|
337
337
|
prefab.log.debug 'Test debug'
|
338
338
|
refute_logged io, 'Test debug'
|
339
339
|
|
@@ -347,7 +347,7 @@ class TestLogger < Minitest::Test
|
|
347
347
|
reset_io(io)
|
348
348
|
|
349
349
|
# with the wrong context, the level should be the default for the env (info)
|
350
|
-
prefab.
|
350
|
+
prefab.with_context(user: { email_suffix: 'yahoo.com' }) do
|
351
351
|
prefab.log.debug 'Test debug'
|
352
352
|
refute_logged io, 'Test debug'
|
353
353
|
|
@@ -361,7 +361,7 @@ class TestLogger < Minitest::Test
|
|
361
361
|
reset_io(io)
|
362
362
|
|
363
363
|
# with the correct context, the level should be the desired value (debug)
|
364
|
-
prefab.
|
364
|
+
prefab.with_context(user: { email_suffix: 'hotmail.com' }) do
|
365
365
|
prefab.log.debug 'Test debug'
|
366
366
|
assert_logged io, 'DEBUG', "#{prefix}.test.test_logger.test_logging_with_criteria_on_key_path", 'Test debug'
|
367
367
|
|
@@ -375,7 +375,7 @@ class TestLogger < Minitest::Test
|
|
375
375
|
reset_io(io)
|
376
376
|
|
377
377
|
# with the correct lookup key
|
378
|
-
prefab.
|
378
|
+
prefab.with_context(user: { tracking_id: 'user:4567' }) do
|
379
379
|
prefab.log.debug 'Test debug'
|
380
380
|
assert_logged io, 'DEBUG', "#{prefix}.test.test_logger.test_logging_with_criteria_on_key_path", 'Test debug'
|
381
381
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prefab-cloud-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.24.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Dwyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -197,6 +197,7 @@ files:
|
|
197
197
|
- lib/prefab/config_loader.rb
|
198
198
|
- lib/prefab/config_resolver.rb
|
199
199
|
- lib/prefab/config_value_unwrapper.rb
|
200
|
+
- lib/prefab/context.rb
|
200
201
|
- lib/prefab/criteria_evaluator.rb
|
201
202
|
- lib/prefab/error.rb
|
202
203
|
- lib/prefab/errors/initialization_timeout_error.rb
|
@@ -213,6 +214,7 @@ files:
|
|
213
214
|
- lib/prefab/noop_cache.rb
|
214
215
|
- lib/prefab/noop_stats.rb
|
215
216
|
- lib/prefab/options.rb
|
217
|
+
- lib/prefab/resolved_config_presenter.rb
|
216
218
|
- lib/prefab/sse_logger.rb
|
217
219
|
- lib/prefab/weighted_value_resolver.rb
|
218
220
|
- lib/prefab/yaml_config_parser.rb
|
@@ -227,6 +229,7 @@ files:
|
|
227
229
|
- test/test_config_loader.rb
|
228
230
|
- test/test_config_resolver.rb
|
229
231
|
- test/test_config_value_unwrapper.rb
|
232
|
+
- test/test_context.rb
|
230
233
|
- test/test_criteria_evaluator.rb
|
231
234
|
- test/test_exponential_backoff.rb
|
232
235
|
- test/test_feature_flag_client.rb
|