process_settings 0.10.6.pre.1 → 0.11.0.pre.1

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: 9f84a7b291c62e80a70aa63c5cd9fef3da8a479023b97b2b48876440e2ad3f78
4
- data.tar.gz: ed14cf885d3c1e8f43aba4efd90b84aae91fba2e7d9aa0c044d3d87d60453ed0
3
+ metadata.gz: 59a90fdb765825b3e33cf5de6ceec5ffba64975aec6ec17062c18f53ca47e350
4
+ data.tar.gz: 30a111bd424743bbe3303fbd76651c160f2f2baae535dbcf1cc243be3339c6b5
5
5
  SHA512:
6
- metadata.gz: db0012a991f04fe39c830010e5d5bb189ab0d4acd7211e04b3c606aa4267297b439ef42837238366a13798bef80a3ba078c192494b2d135b29b5ae80998e16ab
7
- data.tar.gz: 571dd8f98045dd11f43dc4d349d0b3b0e094de80deb304a3a52905c6659e8643f6adf9cc31ae4474bdd55b8530d9698fcaaa940e1d4a21c84461686bdd32b8e0
6
+ metadata.gz: 9c185d646afc5c8ae430e2160f794b3dd29599ab711a5defdbcc0fa669ccac0b09baaa0a1fc0ad0b889400039b59f6c95cd3b5278fdb36c026aa8f74221ef79a
7
+ data.tar.gz: efe2370a36301f6e222037497ee8374d5997499de82dbb2d6a6da20150474598aab99d7cc0035a32cea494bf576ab4ceeaf026b97903dc8ffa782aa6e58923f3
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
  ```
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ProcessSettings
4
- VERSION = '0.10.6.pre.1'
4
+ VERSION = '0.11.0.pre.1'
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.6.pre.1
4
+ version: 0.11.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca