prefab-cloud-ruby 0.24.1 → 0.24.2

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: 9b54e4d5e0b52064cc19b41e33d9c7552cc8534bcab59cc42b48e4fc77fd5b58
4
- data.tar.gz: bd6901fcb99e35fc859ae382fb7d0354c1cd484fb75a1dbba27d0d0e07cdb397
3
+ metadata.gz: 0ba1dd85add1fd682905bb54cfa2ab75baa3f4b3bc1c31fe762d8389b10c8aea
4
+ data.tar.gz: 4fb1d5bdc68d1dcd566afe681b02970288fbdcbbcf5c9706705c3d857b3422d4
5
5
  SHA512:
6
- metadata.gz: 96249d926438ccf2b4c239ae3b65a3649bb8b8e279e05774431376188b9ee330e71211f52bb7a51d5edf457be1997bfb5609e2a91debde4a2719f9ff4f34ae4a
7
- data.tar.gz: fd42fd6be60e9572eb5a857253eabbb44693d46927ecef0b57ed72213c1af875511c4b2ad86bd5e7257e75ac063bde78a49f03f62a0d0350348d18d696d4a59d
6
+ metadata.gz: 0cbdd3e8d1c04b3f113ccbf9a6fdd8f46f3240f71db26d2feb86b18dfbf25237c1df24325aa90d433c20ef017138fd0f847d5599d27e746fc983dac680f1278c
7
+ data.tar.gz: e09ed434ec40557b2ba8b684abdf2da3ae32103715e200162898b002031b9e175a401f9c435424b937d4929302f5dd7066813bdfd8d9fe1048fc6d74579815c9
data/README.md CHANGED
@@ -41,7 +41,7 @@ $prefab.set_rails_loggers
41
41
  ```ruby
42
42
  #puma.rb
43
43
  on_worker_boot do
44
- $prefab = Prefab::Client.new
44
+ $prefab = $prefab.fork
45
45
  $prefab.set_rails_loggers
46
46
  end
47
47
  ```
@@ -49,7 +49,7 @@ end
49
49
  ```ruby
50
50
  # unicorn.rb
51
51
  after_fork do |server, worker|
52
- $prefab = Prefab::Client.new(options)
52
+ $prefab = $prefab.fork
53
53
  $prefab.set_rails_loggers
54
54
  end
55
55
  ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.24.1
1
+ 0.24.2
data/lib/prefab/client.rb CHANGED
@@ -111,6 +111,15 @@ module Prefab
111
111
  config_client.resolver
112
112
  end
113
113
 
114
+ # When starting a forked process, use this to re-use the options
115
+ # on_worker_boot do
116
+ # $prefab = $prefab.fork
117
+ # $prefab.set_rails_loggers
118
+ # end
119
+ def fork
120
+ Prefab::Client.new(@options)
121
+ end
122
+
114
123
  private
115
124
 
116
125
  def is_ff?(key)
@@ -55,10 +55,11 @@ module Prefab
55
55
  end
56
56
 
57
57
  def get(key, default = NO_DEFAULT_PROVIDED, properties = NO_DEFAULT_PROVIDED)
58
- value = _get(key, properties)
58
+ context = @config_resolver.make_context(properties)
59
+ value = _get(key, context)
59
60
 
60
61
  if value
61
- Prefab::ConfigValueUnwrapper.unwrap(value, key, properties)
62
+ Prefab::ConfigValueUnwrapper.unwrap(value, key, context)
62
63
  else
63
64
  handle_default(key, default)
64
65
  end
@@ -42,7 +42,7 @@ module Prefab
42
42
  project_env_id: @project_env_id,
43
43
  resolver: self,
44
44
  namespace: @base_client.options.namespace,
45
- base_client: @base_client).evaluate(context(properties))
45
+ base_client: @base_client).evaluate(make_context(properties))
46
46
  end
47
47
 
48
48
  def update
@@ -55,9 +55,7 @@ module Prefab
55
55
  @on_update = block
56
56
  end
57
57
 
58
- private
59
-
60
- def context(properties)
58
+ def make_context(properties)
61
59
  if properties == NO_DEFAULT_PROVIDED
62
60
  Context.current
63
61
  elsif properties.is_a?(Context)
@@ -67,6 +65,8 @@ module Prefab
67
65
  end
68
66
  end
69
67
 
68
+ private
69
+
70
70
  def make_local
71
71
  @lock.with_write_lock do
72
72
  @local_store = @config_loader.calc_config
@@ -14,7 +14,7 @@ module Prefab
14
14
  value = Prefab::WeightedValueResolver.new(
15
15
  config_value.weighted_values.weighted_values,
16
16
  config_key,
17
- context[config_value.weighted_values.hash_by_property_name]
17
+ context.get(config_value.weighted_values.hash_by_property_name)
18
18
  ).resolve
19
19
 
20
20
  unwrap(value.value, config_key, context)
@@ -77,18 +77,10 @@ module Prefab
77
77
  end
78
78
  end
79
79
 
80
- def merge!(name, hash)
81
- @contexts[name.to_s] = context(name).merge!(hash)
82
- end
83
-
84
80
  def set(name, hash)
85
81
  @contexts[name.to_s] = NamedContext.new(name, hash)
86
82
  end
87
83
 
88
- def []=(name, hash)
89
- set(name, hash)
90
- end
91
-
92
84
  def get(property_key)
93
85
  name, key = property_key.split('.', 2)
94
86
 
@@ -100,10 +92,6 @@ module Prefab
100
92
  contexts[name] && contexts[name].get(key)
101
93
  end
102
94
 
103
- def [](property_key)
104
- get(property_key)
105
- end
106
-
107
95
  def to_h
108
96
  contexts.map { |name, context| [name, context.to_h] }.to_h
109
97
  end
@@ -45,7 +45,7 @@ module Prefab
45
45
  hash[k] = ConfigRow.new(k, nil, nil, nil)
46
46
  else
47
47
  config = @resolver.evaluate(v[:config])
48
- value = Prefab::ConfigValueUnwrapper.unwrap(config, k, {})
48
+ value = Prefab::ConfigValueUnwrapper.unwrap(config, k, Prefab::Context.new)
49
49
  hash[k] = ConfigRow.new(k, value, v[:match], v[:source])
50
50
  end
51
51
  end
@@ -67,7 +67,7 @@ module Prefab
67
67
  elements << 'tombstone'
68
68
  else
69
69
  config = @resolver.evaluate(v[:config], {})
70
- value = Prefab::ConfigValueUnwrapper.unwrap(config, k, {})
70
+ value = Prefab::ConfigValueUnwrapper.unwrap(config, k, Prefab::Context.new)
71
71
  elements << value.to_s.slice(0..34).ljust(35)
72
72
  elements << value.class.to_s.slice(0..6).ljust(7)
73
73
  elements << "Match: #{v[:match]}".slice(0..29).ljust(30)
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: prefab-cloud-ruby 0.24.1 ruby lib
5
+ # stub: prefab-cloud-ruby 0.24.2 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "prefab-cloud-ruby".freeze
9
- s.version = "0.24.1"
9
+ s.version = "0.24.2"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Jeff Dwyer".freeze]
14
- s.date = "2023-04-26"
14
+ s.date = "2023-05-12"
15
15
  s.description = "Feature Flags, Live Config, and Dynamic Log Levels as a service".freeze
16
16
  s.email = "jdwyer@prefab.cloud".freeze
17
17
  s.extra_rdoc_files = [
@@ -12,7 +12,9 @@ class IntegrationTest
12
12
  end
13
13
 
14
14
  def test_type
15
- if @expected[:status] == 'raise'
15
+ if @input[0] && @input[0].start_with?('log-level.')
16
+ :log_level
17
+ elsif @expected[:status] == 'raise'
16
18
  :raise
17
19
  elsif @expected[:value].nil?
18
20
  :nil
@@ -4,45 +4,46 @@ require 'test_helper'
4
4
 
5
5
  class TestConfigValueUnwrapper < Minitest::Test
6
6
  CONFIG_KEY = 'config_key'
7
+ EMPTY_CONTEXT = Prefab::Context.new()
7
8
 
8
9
  def test_unwrapping_int
9
10
  config_value = Prefab::ConfigValue.new(int: 123)
10
- assert_equal 123, Prefab::ConfigValueUnwrapper.unwrap(config_value, CONFIG_KEY, {})
11
+ assert_equal 123, Prefab::ConfigValueUnwrapper.unwrap(config_value, CONFIG_KEY, EMPTY_CONTEXT)
11
12
  end
12
13
 
13
14
  def test_unwrapping_string
14
15
  config_value = Prefab::ConfigValue.new(string: 'abc')
15
- assert_equal 'abc', Prefab::ConfigValueUnwrapper.unwrap(config_value, CONFIG_KEY, {})
16
+ assert_equal 'abc', Prefab::ConfigValueUnwrapper.unwrap(config_value, CONFIG_KEY, EMPTY_CONTEXT)
16
17
  end
17
18
 
18
19
  def test_unwrapping_double
19
20
  config_value = Prefab::ConfigValue.new(double: 1.23)
20
- assert_equal 1.23, Prefab::ConfigValueUnwrapper.unwrap(config_value, CONFIG_KEY, {})
21
+ assert_equal 1.23, Prefab::ConfigValueUnwrapper.unwrap(config_value, CONFIG_KEY, EMPTY_CONTEXT)
21
22
  end
22
23
 
23
24
  def test_unwrapping_bool
24
25
  config_value = Prefab::ConfigValue.new(bool: true)
25
- assert_equal true, Prefab::ConfigValueUnwrapper.unwrap(config_value, CONFIG_KEY, {})
26
+ assert_equal true, Prefab::ConfigValueUnwrapper.unwrap(config_value, CONFIG_KEY, EMPTY_CONTEXT)
26
27
 
27
28
  config_value = Prefab::ConfigValue.new(bool: false)
28
- assert_equal false, Prefab::ConfigValueUnwrapper.unwrap(config_value, CONFIG_KEY, {})
29
+ assert_equal false, Prefab::ConfigValueUnwrapper.unwrap(config_value, CONFIG_KEY, EMPTY_CONTEXT)
29
30
  end
30
31
 
31
32
  def test_unwrapping_log_level
32
33
  config_value = Prefab::ConfigValue.new(log_level: :INFO)
33
- assert_equal :INFO, Prefab::ConfigValueUnwrapper.unwrap(config_value, CONFIG_KEY, {})
34
+ assert_equal :INFO, Prefab::ConfigValueUnwrapper.unwrap(config_value, CONFIG_KEY, EMPTY_CONTEXT)
34
35
  end
35
36
 
36
37
  def test_unwrapping_string_list
37
38
  config_value = Prefab::ConfigValue.new(string_list: Prefab::StringList.new(values: %w[a b c]))
38
- assert_equal %w[a b c], Prefab::ConfigValueUnwrapper.unwrap(config_value, CONFIG_KEY, {})
39
+ assert_equal %w[a b c], Prefab::ConfigValueUnwrapper.unwrap(config_value, CONFIG_KEY, EMPTY_CONTEXT)
39
40
  end
40
41
 
41
42
  def test_unwrapping_weighted_values
42
43
  # single value
43
44
  config_value = Prefab::ConfigValue.new(weighted_values: weighted_values([['abc', 1]]))
44
45
 
45
- assert_equal 'abc', Prefab::ConfigValueUnwrapper.unwrap(config_value, CONFIG_KEY, {})
46
+ assert_equal 'abc', Prefab::ConfigValueUnwrapper.unwrap(config_value, CONFIG_KEY, EMPTY_CONTEXT)
46
47
 
47
48
  # multiple values, evenly distributed
48
49
  config_value = Prefab::ConfigValue.new(weighted_values: weighted_values([['abc', 1], ['def', 1], ['ghi', 1]]))
data/test/test_context.rb CHANGED
@@ -86,7 +86,7 @@ class TestContext < Minitest::Test
86
86
  Prefab::Context.with_context(EXAMPLE_PROPERTIES) do
87
87
  context = Prefab::Context.current
88
88
  assert_equal(stringify(EXAMPLE_PROPERTIES), context.to_h)
89
- assert_equal('some-user-key', context['user.key'])
89
+ assert_equal('some-user-key', context.get('user.key'))
90
90
  end
91
91
  end
92
92
 
@@ -105,34 +105,24 @@ class TestContext < Minitest::Test
105
105
  def test_setting
106
106
  context = Prefab::Context.new({})
107
107
  context.set('user', { key: 'value' })
108
- context[:other] = { key: 'different', something: 'other' }
108
+ context.set(:other, { key: 'different', something: 'other' })
109
109
  assert_equal(stringify({ user: { key: 'value' }, other: { key: 'different', something: 'other' } }), context.to_h)
110
110
  end
111
111
 
112
112
  def test_getting
113
113
  context = Prefab::Context.new(EXAMPLE_PROPERTIES)
114
114
  assert_equal('some-user-key', context.get('user.key'))
115
- assert_equal('some-user-key', context['user.key'])
116
115
  assert_equal('pro', context.get('team.plan'))
117
- assert_equal('pro', context['team.plan'])
118
116
  end
119
117
 
120
118
  def test_dot_notation_getting
121
119
  context = Prefab::Context.new({ 'user' => { 'key' => 'value' } })
122
120
  assert_equal('value', context.get('user.key'))
123
- assert_equal('value', context['user.key'])
124
121
  end
125
122
 
126
123
  def test_dot_notation_getting_with_symbols
127
124
  context = Prefab::Context.new({ user: { key: 'value' } })
128
125
  assert_equal('value', context.get('user.key'))
129
- assert_equal('value', context['user.key'])
130
- end
131
-
132
- def test_merge
133
- context = Prefab::Context.new(EXAMPLE_PROPERTIES)
134
- context.merge!(:other, { key: 'different' })
135
- assert_equal(stringify(EXAMPLE_PROPERTIES.merge(other: { key: 'different' })), context.to_h)
136
126
  end
137
127
 
138
128
  def test_clear
@@ -13,7 +13,7 @@ class TestIntegration < Minitest::Test
13
13
  parent_context = test['context']
14
14
 
15
15
  test['cases'].each do |test_case|
16
- define_method(:"test_#{test_case['name']}") do
16
+ define_method(:"test_#{test['name']}_#{test_case['name']}") do
17
17
  it = IntegrationTest.new(test_case)
18
18
 
19
19
  with_parent_context_maybe(parent_context) do
@@ -30,6 +30,10 @@ class TestIntegration < Minitest::Test
30
30
  assert_equal it.expected[:value], it.test_client.send(it.func, flag, context)
31
31
  when :simple_equality
32
32
  assert_equal it.expected[:value], it.test_client.send(it.func, *it.input)
33
+ when :log_level
34
+ assert_equal it.expected[:value].to_sym, it.test_client.send(it.func, *it.input)
35
+ else
36
+ raise "Unknown test type: #{it.test_type}"
33
37
  end
34
38
  end
35
39
  end
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.24.1
4
+ version: 0.24.2
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-26 00:00:00.000000000 Z
11
+ date: 2023-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby