process_settings 0.10.4 → 0.11.0.pre.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +20 -23
- data/lib/process_settings.rb +2 -9
- data/lib/process_settings/abstract_monitor.rb +1 -1
- data/lib/process_settings/file_monitor.rb +22 -1
- data/lib/process_settings/monitor.rb +7 -3
- data/lib/process_settings/target.rb +1 -1
- data/lib/process_settings/testing/helpers.rb +14 -3
- data/lib/process_settings/testing/monitor_stub.rb +7 -1
- data/lib/process_settings/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef299e8fb9e1a8fca1ebd84a990a2ec84dea17272583f3f1e34858d26a19d0a1
|
4
|
+
data.tar.gz: ff4d958303e70f14eb292835e7c84d752fc2479d20987ad15d0feb430d5b3ad7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03125f52588f94606ef8d740c23a3eed4eaf69fc0d7025e3ac34b03c030003ddb87949c4c7a6afbb73e5886bcc34e57948d596a9c0639d4083fc5be8c5f659c7
|
7
|
+
data.tar.gz: b7154fdbf0e3376f1bfaff788779c44839648086ece0b2a4eee8f354d475ce2180e9a2c6d12c4c4ad0e6b82f56572e3a9c21ae473f4e798f14af1fd609e1d189
|
data/README.md
CHANGED
@@ -21,25 +21,25 @@ gem 'process_settings', '~> 0.4'
|
|
21
21
|
```
|
22
22
|
|
23
23
|
## Usage
|
24
|
-
The `ProcessSettings::
|
25
|
-
But typical usage is through the `ProcessSettings
|
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
|
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
|
34
|
-
|
33
|
+
ProcessSettings.instance = ProcessSettings::FileMonitor.new("/etc/process_settings/combined_process_settings.yml",
|
34
|
+
logger: logger)
|
35
35
|
```
|
36
|
-
###
|
37
|
-
The `ProcessSettings
|
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
|
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
|
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::
|
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
|
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
|
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
|
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
|
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
|
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
|
```
|
data/lib/process_settings.rb
CHANGED
@@ -22,14 +22,14 @@ module ProcessSettings
|
|
22
22
|
raise ArgumentError, "Invalid monitor of type #{monitor.class.name} provided. Must be of type ProcessSettings::AbstractMonitor"
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
Monitor.instance = monitor
|
26
26
|
end
|
27
27
|
|
28
28
|
# Getter method for retrieving the current monitor instance being used by ProcessSettings
|
29
29
|
#
|
30
30
|
# @return [ProcessSettings::AbstractMonitor]
|
31
31
|
def instance
|
32
|
-
|
32
|
+
Monitor.instance
|
33
33
|
end
|
34
34
|
|
35
35
|
# This is the main entry point for looking up settings in the process.
|
@@ -56,12 +56,5 @@ module ProcessSettings
|
|
56
56
|
def [](*path, dynamic_context: {}, required: true)
|
57
57
|
instance[*path, dynamic_context: dynamic_context, required: required]
|
58
58
|
end
|
59
|
-
|
60
|
-
private
|
61
|
-
|
62
|
-
def lazy_create_instance
|
63
|
-
ActiveSupport::Deprecation.warn("lazy creation of Monitor instance is deprecated and will be removed from ProcessSettings 1.0")
|
64
|
-
Monitor.instance
|
65
|
-
end
|
66
59
|
end
|
67
60
|
end
|
@@ -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
|
-
|
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.environment) || 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
|
-
|
35
|
-
|
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
|
36
39
|
end
|
37
40
|
|
38
41
|
def default_instance
|
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
|
|
@@ -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
|
|
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.
|
4
|
+
version: 0.11.0.pre.3
|
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:
|
113
|
+
version: 1.3.1
|
114
114
|
requirements: []
|
115
115
|
rubygems_version: 3.0.3
|
116
116
|
signing_key:
|