process_settings 0.5.1 → 0.5.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: a9c510ffc0718c9a0cc8db0052d7abe3a9d08669567b7ddfee82a3f8666ed9f3
4
- data.tar.gz: 535c278059881ae7cfbbe671266e42cb2f7b5d78d16f369caad13096ca0db03d
3
+ metadata.gz: d346028f0e5292862f740f24b653940c321d802eeb52cec982dd5b8db2a3152e
4
+ data.tar.gz: 9eb2b3d22bedacf239a777ee23606badf82c664d2b69cc28067bd47aaef6e90f
5
5
  SHA512:
6
- metadata.gz: 8635354029bce4a6dfa49d00c21e20eb17dd095dbe16b32aaaf1b249323d28ffbeb0f8adbd9cbc2a060ff046d92a19b77a8708d8df5bcc7704e45352135cffa8
7
- data.tar.gz: 405d6a5d9e155b196e7ac1beed18493cb00630be74919db79ef2005ef0e201ae9a9c01991b58b07b00ce9a5d01cfc489aad80dfceabe556b8e3245685bfd02d6
6
+ metadata.gz: 38e4b19aa83dd76fd8ba875bc8aad8c96e924e8dc44eaf080f7dcb42cb20c8c761fe31b9e691d5547df8c3eb9ba1111696e6bf04251cbd2462681f685ea77574
7
+ data.tar.gz: 69fe761830b9ae703a6a976590d641b289b26fa95add7e1b6258ad72736f528aa871f2c77de3f3119f9a143adb0b3f45df5c9b4dba6af4b05820dd29abc7212f
data/README.md CHANGED
@@ -3,7 +3,7 @@ This gem provides dynamic settings for Ruby processes. The settings are stored i
3
3
  Settings are managed in a git repo, in separate YAML files for each concern (for example, each micro-service). Each YAML file can be targeted based on matching context values (for example, `service_name`).
4
4
 
5
5
 
6
- The context can be either static to the process (for example, `service_name` or `data_center`) or dynamic (for example, the current web request `domain`).
6
+ The context can be either static to the process (for example, `service_name` or `datacenter`) or dynamic (for example, the current web request `domain`).
7
7
 
8
8
  ## Installation
9
9
  To install this gem directly on your machine from rubygems, run the following:
@@ -37,7 +37,7 @@ The monitor should be initialized with static (unchanging) context for your proc
37
37
  ```
38
38
  ProcessSettings::Monitor.static_context = {
39
39
  "service_name" => "frontend",
40
- "data_center" => "AWS-US-EAST-1"
40
+ "datacenter" => "AWS-US-EAST-1"
41
41
  }
42
42
  ```
43
43
  The `static_context` is important because it is used to pre-filter settings for the process.
@@ -143,22 +143,38 @@ To `target` on context values, provide a hash of key-value pairs. All keys must
143
143
  ```
144
144
  target:
145
145
  service_name: frontend
146
- data_center: AWS-US-EAST-1
146
+ datacenter: AWS-US-EAST-1
147
147
  ```
148
- This will be applied in any process that has `service_name == "frontend"` AND is running in `data_center == "AWS-US-EAST-1"`.
148
+ This will be applied in any process that has `service_name == "frontend"` AND is running in `datacenter == "AWS-US-EAST-1"`.
149
149
 
150
150
  ### Multiple Values Are OR'd
151
151
  Values may be set to an array, in which case the key matches if _any_ of the values matches. For example, consider this target hash:
152
152
  ```
153
153
  target:
154
154
  service_name: [frontend, auth]
155
- data_center: AWS-US-EAST-1
155
+ datacenter: AWS-US-EAST-1
156
156
  ```
157
- This will be applied in any process that has (`service_name == "frontend"` OR `service_name == "auth"`) AND `data_center == "AWS-US-EAST-1"`.
157
+ This will be applied in any process that has (`service_name == "frontend"` OR `service_name == "auth"`) AND `datacenter == "AWS-US-EAST-1"`.
158
158
 
159
159
  ### Precedence
160
160
  The settings YAML files are always combined in alphabetical order by file path. Later settings take precedence over the earlier ones.
161
161
 
162
+ ### Testing
163
+ For testing, it is often necessary to set a specific hash for the process_settings values to use in that test case.
164
+ The `ProcessSettings::Testing::MonitorStub` class is provided for this purpose. It can be initialized with a hash and assigned to `ProcessSettings::Monitor.instance`. After the test runs, make sure to call `clear_instance`.
165
+ Note that it has no `targeting` or `settings` keys; it is stubbing the resulting settings hash _after_ targeting has been applied.
166
+ Here is an example using `rspec` conventions:
167
+ ```
168
+ before do
169
+ settings = { "honeypot" => { "answer_odds" => 100 } }
170
+ ProcessSettings::Monitor.instance = ProcessSettings::Testing::MonitorStub.new(settings)
171
+ end
172
+
173
+ after do
174
+ ProcessSettings::Monitor.clear_instance
175
+ end
176
+ ```
177
+
162
178
  ## Contributions
163
179
 
164
180
  Contributions to this project are always welcome. Please thoroughly read our [Contribution Guidelines](https://github.com/Invoca/process_settings/blob/master/CONTRIBUTING.md) before starting any work.
@@ -62,14 +62,14 @@ flat_services_yml_json_doc.each do |service, nodes|
62
62
  if (changed = node_targeted_process_settings_old != node_targeted_process_settings_new)
63
63
  node_old = node_targeted_process_settings_old.map do |node_targeted_process_setting|
64
64
  {
65
- 'target' => node_targeted_process_setting.target,
66
- "process_settings" => node_targeted_process_setting.process_settings
65
+ 'target' => node_targeted_process_setting.target,
66
+ "settings" => node_targeted_process_setting.settings
67
67
  }
68
68
  end
69
69
  node_new = node_targeted_process_settings_new.map do |node_targeted_process_setting|
70
70
  {
71
- 'target' => node_targeted_process_setting.target,
72
- "process_settings" => node_targeted_process_setting.process_settings
71
+ 'target' => node_targeted_process_setting.target,
72
+ "settings" => node_targeted_process_setting.settings
73
73
  }
74
74
  end
75
75
 
@@ -81,7 +81,7 @@ module ProcessSettings
81
81
  result = statically_targeted_settings.reduce(:not_found) do |latest_result, target_and_settings|
82
82
  # find last value from matching targets
83
83
  if target_and_settings.target.target_key_matches?(full_context)
84
- if (value = target_and_settings.process_settings.json_doc.mine(*path, not_found_value: :not_found)) != :not_found
84
+ if (value = target_and_settings.settings.json_doc.mine(*path, not_found_value: :not_found)) != :not_found
85
85
  latest_result = value
86
86
  end
87
87
  end
@@ -6,7 +6,7 @@ require_relative 'settings'
6
6
  module ProcessSettings
7
7
  # This class encapsulates a single YAML file with target and process_settings.
8
8
  class TargetAndSettings
9
- attr_reader :filename, :target, :process_settings
9
+ attr_reader :filename, :target, :settings
10
10
 
11
11
  def initialize(filename, target, settings)
12
12
  @filename = filename
@@ -15,7 +15,7 @@ module ProcessSettings
15
15
  @target = target
16
16
 
17
17
  settings.is_a?(Settings) or raise ArgumentError, "settings must be a ProcessSettings; got #{settings.inspect}"
18
- @process_settings = settings
18
+ @settings = settings
19
19
  end
20
20
 
21
21
  def ==(rhs)
@@ -29,7 +29,7 @@ module ProcessSettings
29
29
  def to_json_doc
30
30
  {
31
31
  "target" => @target.json_doc,
32
- "settings" => @process_settings.json_doc
32
+ "settings" => @settings.json_doc
33
33
  }
34
34
  end
35
35
 
@@ -37,9 +37,9 @@ module ProcessSettings
37
37
  def from_json_docs(filename, target_json_doc, settings_json_doc)
38
38
  target_json_doc = Target.new(target_json_doc)
39
39
 
40
- process_settings = Settings.new(settings_json_doc)
40
+ settings = Settings.new(settings_json_doc)
41
41
 
42
- new(filename, target_json_doc, process_settings)
42
+ new(filename, target_json_doc, settings)
43
43
  end
44
44
  end
45
45
 
@@ -49,7 +49,7 @@ module ProcessSettings
49
49
  if new_target == @target
50
50
  self
51
51
  else
52
- self.class.new(@filename, new_target, @process_settings)
52
+ self.class.new(@filename, new_target, @settings)
53
53
  end
54
54
  end
55
55
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ProcessSettings
4
- VERSION = '0.5.1'
4
+ VERSION = '0.5.2'
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.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca
@@ -86,6 +86,7 @@ licenses:
86
86
  - MIT
87
87
  metadata:
88
88
  source_code_uri: https://github.com/Invoca/process_settings
89
+ allowed_push_host: https://rubygems.org
89
90
  post_install_message:
90
91
  rdoc_options: []
91
92
  require_paths: