process_settings 0.10.5 → 0.11.0.pre.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: 22513a938b872f9e3366d445d4c121aafd965c32bec9b937f9b2abe41ff73722
4
- data.tar.gz: 4e352a2f5a80c19fd171810612b411762372aec422464f684cbcfe71d5d27602
3
+ metadata.gz: 00cb781d3385028324b7dd6f55e12da7550901107adf78ee57abde78987335b4
4
+ data.tar.gz: b8ae66252379583f2ac9a8da599e54d559fbd92d4d40b12d36faa6539114e511
5
5
  SHA512:
6
- metadata.gz: ac2cf3d580dd5c27c4bed2a10a59024d886bcfecd2cae4a2b39ddc3e34b78a82f41e01323bc0732144c4bd2823c1e379c2bd218ebf34cf4dc2b1a992d9bf9b20
7
- data.tar.gz: 97b556d773340f019947a3c623faea53086274a8ff03b62b61583c757e3d7228acb0d1b800ad21076831648238dcca008f7a0cf939ade944d33fc3832b78828d
6
+ metadata.gz: c0229a56f9a6e8f6fe20fa0b19cdb82f2df4d82dbd3abd0c7d74cd0b136200e7ac48a261252b60fcd467f6b0c8a8967e8b62e6237f8cf737d871edbc8c0db189
7
+ data.tar.gz: 528650ea37e3fa716b588d76d5cef31af6e06e6d5fd506b4f7b65f13d51e38fd45a3f65a3c004cff0e294df47ec9397c29870dd26cdba0ea05ec5b80ef21bb3e
data/README.md CHANGED
@@ -21,25 +21,25 @@ gem 'process_settings', '~> 0.4'
21
21
  ```
22
22
 
23
23
  ## Usage
24
- The `ProcessSettings::Monitor` and related classes can be freely created and used at any time.
25
- But typical usage is through the `ProcessSettings::Monitor.instance`.
24
+ The `ProcessSettings::FileMonitor` and related classes can be freely created and used at any time.
25
+ But typical usage is through the `ProcessSettings.instance`.
26
26
  That should be configured at process startup before use.
27
27
  ### Configuration
28
- Before using `ProcessSettings::Monitor.instance`, you must first configure the path to the combined process settings file on disk,
28
+ Before using `ProcessSettings.instance`, you must first configure the path to the combined process settings file on disk,
29
29
  and provide a logger.
30
30
  ```ruby
31
31
  require 'process_settings'
32
32
 
33
- ProcessSettings::Monitor.file_path = "/etc/process_settings/combined_process_settings.yml"
34
- ProcessSettings::Monitor.logger = logger
33
+ ProcessSettings.instance = ProcessSettings::FileMonitor.new("/etc/process_settings/combined_process_settings.yml",
34
+ logger: logger)
35
35
  ```
36
- ### Monitor Initialization
37
- The `ProcessSettings::Monitor` is a hybrid singleton. The class attribute `instance` returns
38
- the current instance. If not already set, this is lazy-created based on the above configuration.
36
+ ### Instance Initialization
37
+ The `ProcessSettings` is a hybrid singleton. The class attribute `instance` returns
38
+ the current instance as set at configuration time. Deprecated: If not already set, this is lazy-created based on the above configuration.
39
39
 
40
40
  The monitor should be initialized with static (unchanging) context for your process:
41
41
  ```
42
- ProcessSettings::Monitor.static_context = {
42
+ ProcessSettings.instance.static_context = {
43
43
  "service_name" => "frontend",
44
44
  "datacenter" => "AWS-US-EAST-1"
45
45
  }
@@ -76,7 +76,7 @@ log_level = ProcessSettings['frontend', 'log_level']
76
76
  => "info"
77
77
  ```
78
78
  #### ProcessSettings[] interface
79
- The `ProcessSettings[]` method delegates to `ProcessSettings::Monitor#[]` on the `instance`.
79
+ The `ProcessSettings[]` method delegates to `ProcessSettings.instance#[]` on the `instance`.
80
80
 
81
81
  `[]` interface:
82
82
 
@@ -114,22 +114,22 @@ http_version = ProcessSettings['frontend', 'http_version', required: false] || 2
114
114
 
115
115
  ### Dynamic Settings
116
116
 
117
- The `ProcessSettings::Monitor` loads settings changes dynamically whenever the file changes,
117
+ The `ProcessSettings::FileMonitor` loads settings changes dynamically whenever the file changes,
118
118
  by using the [listen](https://github.com/guard/listen) gem which in turn uses the `INotify` module of the Linux kernel, or `FSEvents` on MacOS. There is no need to restart the process or send it a signal to tell it to reload changes.
119
119
 
120
120
  There are two ways to get access the latest settings from inside the process:
121
121
 
122
122
  #### Read Latest Setting Through `ProcessSettings[]`
123
123
 
124
- The simplest approach--as shown above--is to read the latest settings at any time through `ProcessSettings[]` (which delegates to `ProcessSettings::Monitor.instance`):
124
+ The simplest approach--as shown above--is to read the latest settings at any time through `ProcessSettings[]` (which delegates to `ProcessSettings.instance`):
125
125
  ```
126
126
  http_version = ProcessSettings['frontend', 'http_version']
127
127
  ```
128
128
 
129
129
  #### Register an `on_change` Callback
130
- Alternatively, if you need to execute some code when there is a change, register a callback with `ProcessSettings::Monitor#on_change`:
130
+ Alternatively, if you need to execute some code when there is a change, register a callback with `ProcessSettings.instance#on_change`:
131
131
  ```
132
- ProcessSettings::Monitor.instance.on_change do
132
+ ProcessSettings.instance.on_change do
133
133
  logger.level = ProcessSettings['frontend', 'log_level']
134
134
  end
135
135
  ```
@@ -166,7 +166,7 @@ The settings YAML files are always combined in alphabetical order by file path.
166
166
  ### Testing
167
167
  For testing, it is often necessary to set a specific override hash for the process_settings values to use in
168
168
  that use case. The `ProcessSettings::Testing::Helpers` module is provided for this purpose. It can be used to
169
- override a specific hash of process settings, while leving the rest in tact, and resetting back to the defaults
169
+ override a specific hash of process settings, while leaving the rest intact, and resetting back to the defaults
170
170
  after the test case is over. Here are some examples using various testing frameworks:
171
171
 
172
172
  #### RSpec
@@ -179,10 +179,7 @@ RSpec.configure do |config|
179
179
 
180
180
  include ProcessSettings::Testing::Helpers
181
181
 
182
- after do
183
- reset_process_settings
184
- end
185
-
182
+ # Note: the include above will automatically register a global after block that will reset process_settings to their initial values.
186
183
  # ...
187
184
  end
188
185
  ```
@@ -205,14 +202,14 @@ end
205
202
  require 'process_settings/testing/helpers'
206
203
 
207
204
  context SomeClass do
205
+ include ProcessSettings::Testing::Helpers
206
+
207
+ # Note: the include above will automatically register a teardown block that will reset process_settings to their initial values.
208
+
208
209
  setup do
209
210
  stub_process_settings(honeypot: { answer_odds: 100 })
210
211
  end
211
212
 
212
- teardown do
213
- reset_process_settings
214
- end
215
-
216
213
  # ...
217
214
  end
218
215
  ```
@@ -15,7 +15,7 @@ module ProcessSettings
15
15
  attr_reader :static_context, :statically_targeted_settings
16
16
 
17
17
  def initialize(logger:)
18
- @logger = logger
18
+ @logger = logger or raise ArgumentError, "logger must be not be nil"
19
19
  @on_change_callbacks = []
20
20
  @when_updated_blocks = Set.new
21
21
  @static_context = {}
@@ -45,7 +45,7 @@ module ProcessSettings
45
45
  end
46
46
  end
47
47
 
48
- unless ENV['DISABLE_LISTEN_CHANGE_MONITORING']
48
+ if enable_listen_thread?
49
49
  @listener.start
50
50
  end
51
51
 
@@ -58,8 +58,29 @@ module ProcessSettings
58
58
  @listener&.stop
59
59
  end
60
60
 
61
+ def enable_listen_thread?
62
+ !disable_listen_thread?
63
+ end
64
+
65
+ def disable_listen_thread?
66
+ case ENV['DISABLE_LISTEN_CHANGE_MONITORING']
67
+ when 'true', '1'
68
+ true
69
+ when 'false', '0'
70
+ false
71
+ when nil
72
+ service_env == 'test'
73
+ else
74
+ raise ArgumentError, "DISABLE_LISTEN_CHANGE_MONITORING has unknown value #{ENV['DISABLE_LISTEN_CHANGE_MONITORING'].inspect}"
75
+ end
76
+ end
77
+
61
78
  private
62
79
 
80
+ def service_env
81
+ (defined?(Rails) && Rails.env) || ENV['SERVICE_ENV']
82
+ end
83
+
63
84
  # Loads the most recent settings from disk
64
85
  def load_untargeted_settings
65
86
  new_untargeted_settings = load_file(file_path)
@@ -13,7 +13,6 @@ module ProcessSettings
13
13
  attr_writer :instance
14
14
 
15
15
  def file_path=(new_file_path)
16
- ActiveSupport::Deprecation.warn("ProcessSettings::Monitor.file_path= is deprecated and will be removed in v1.0.")
17
16
  clear_instance
18
17
 
19
18
  @file_path = new_file_path
@@ -31,11 +30,16 @@ module ProcessSettings
31
30
  end
32
31
 
33
32
  def instance
34
- @instance ||= default_instance
33
+ if @instance
34
+ @instance
35
+ else
36
+ ActiveSupport::Deprecation.warn("`ProcessSettings::Monitor.instance` lazy create is deprecated and will be removed in v1.0. Assign a `FileMonitor` object to `ProcessSettings.instance =` instead.")
37
+ @instance = default_instance
38
+ end
35
39
  end
36
40
 
37
41
  def default_instance
38
- ActiveSupport::Deprecation.warn("`ProcessSettings::Monitor.instance` is deprecated and will be removed in v1.0. Assign a `FileMonitor` object to `ProcessSettings.instance` instead.")
42
+ ActiveSupport::Deprecation.warn("`ProcessSettings::Monitor.instance` is deprecated and will be removed in v1.0. Assign a `FileMonitor` object to `ProcessSettings.instance =` instead.")
39
43
  @default_instance ||= new_from_settings
40
44
  end
41
45
 
@@ -98,7 +98,7 @@ module ProcessSettings
98
98
 
99
99
  class << self
100
100
  def true_target
101
- @true_target || new(TRUE_JSON_DOC)
101
+ @true_target ||= new(TRUE_JSON_DOC)
102
102
  end
103
103
  end
104
104
  end
@@ -9,7 +9,20 @@ require 'process_settings/testing/monitor'
9
9
  module ProcessSettings
10
10
  module Testing
11
11
  module Helpers
12
-
12
+ class << self
13
+ def included(including_klass)
14
+ after_method =
15
+ if including_klass.respond_to?(:teardown)
16
+ :teardown
17
+ else
18
+ :after
19
+ end
20
+
21
+ including_klass.send(after_method) do
22
+ ProcessSettings.instance = initial_instance
23
+ end
24
+ end
25
+ end
13
26
  # Adds the given settings_hash as an override at the end of the process_settings array, with default targeting (true).
14
27
  # Therefore this will override these settings while leaving others alone.
15
28
  #
@@ -34,8 +47,6 @@ module ProcessSettings
34
47
  )
35
48
  end
36
49
 
37
- private
38
-
39
50
  def initial_instance
40
51
  @initial_instance ||= ProcessSettings.instance
41
52
  end
@@ -11,8 +11,14 @@ module ProcessSettings
11
11
  module Testing
12
12
  # This class implements the Monitor#targeted_value interface but is stubbed to use a simple hash in tests
13
13
  class MonitorStub
14
+ class << self
15
+ def new(*_args)
16
+ ActiveSupport::Deprecation.warn("ProcessSettings::Testing::MonitorStub is deprecated and will be removed in future versions. Use ProcessSettings::Testing::Monitor instead.", caller)
17
+ super
18
+ end
19
+ end
20
+
14
21
  def initialize(settings_hash)
15
- ActiveSupport::Deprecation.warn("ProcessSettings::Testing::MonitorStub is deprecated and will be removed in future versions. Use ProcessSettings::Testing::Monitor instead.", caller)
16
22
  @settings_hash = HashWithHashPath[settings_hash]
17
23
  end
18
24
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ProcessSettings
4
- VERSION = '0.10.5'
4
+ VERSION = '0.11.0.pre.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: process_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.5
4
+ version: 0.11.0.pre.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca
@@ -108,9 +108,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  requirements:
111
- - - ">="
111
+ - - ">"
112
112
  - !ruby/object:Gem::Version
113
- version: '0'
113
+ version: 1.3.1
114
114
  requirements: []
115
115
  rubygems_version: 3.0.3
116
116
  signing_key: