process_settings 0.6.0 → 0.7.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/process_settings/monitor.rb +41 -7
- 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: f2b30454f2b5c672186e76fa87b45aa330d62fd3c09e96366c4377f4b397ea36
|
4
|
+
data.tar.gz: 5bae6a21f59d81f3f365857e5e95fe4cc95b9b047825cd734d5541326ede4a25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f928a7ba0fdf1d1050445c363b67ef95b7c3d0c1a2e2a7f79cbf7cf32b06c9aa18172952b7f2e5c364b4f0cedbd2aeb3795466499b141a27a0ebe57e4627979
|
7
|
+
data.tar.gz: 26c3b75186e76c80e90e380c6da0433822999acffadb702a5d36b71f284aac27da099a952f596543c4728953036e9742bd6ba70629851fa4098e1d46d14c475e
|
@@ -9,6 +9,8 @@ require 'active_support'
|
|
9
9
|
module ProcessSettings
|
10
10
|
class SettingsPathNotFound < StandardError; end
|
11
11
|
|
12
|
+
OnChangeDeprecation = ActiveSupport::Deprecation.new('1.0', 'ProcessSettings::Monitor')
|
13
|
+
|
12
14
|
class Monitor
|
13
15
|
attr_reader :file_path, :min_polling_seconds, :logger
|
14
16
|
attr_reader :static_context, :untargeted_settings, :statically_targeted_settings
|
@@ -19,6 +21,7 @@ module ProcessSettings
|
|
19
21
|
@file_path = File.expand_path(file_path)
|
20
22
|
@logger = logger
|
21
23
|
@on_change_callbacks = []
|
24
|
+
@when_updated_blocks = Set.new
|
22
25
|
@static_context = {}
|
23
26
|
@last_statically_targetted_settings = nil
|
24
27
|
@untargeted_settings = nil
|
@@ -63,15 +66,35 @@ module ProcessSettings
|
|
63
66
|
@listener&.stop
|
64
67
|
end
|
65
68
|
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
+
# Idempotently adds the given block to the when_updated collection
|
70
|
+
# calls the block first unless initial_update: false is passed
|
71
|
+
# returns a handle (the block itself) which can later be passed into cancel_when_updated
|
72
|
+
def when_updated(initial_update: true, &block)
|
73
|
+
if @when_updated_blocks.add?(block)
|
74
|
+
if initial_update
|
75
|
+
begin
|
76
|
+
block.call(self)
|
77
|
+
rescue => ex
|
78
|
+
logger.error("ProcessSettings::Monitor#when_updated rescued exception during initialization:\n#{ex.class}: #{ex.message}")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
block
|
84
|
+
end
|
85
|
+
|
86
|
+
# removes the given when_updated block identified by the handle returned from when_updated
|
87
|
+
def cancel_when_updated(handle)
|
88
|
+
@when_updated_blocks.delete_if { |callback| callback.eql?(handle) }
|
89
|
+
end
|
69
90
|
|
70
91
|
# Registers the given callback block to be called when settings change.
|
71
92
|
# These are run using the shared thread that monitors for changes so be courteous and don't monopolize it!
|
93
|
+
# @deprecated
|
72
94
|
def on_change(&callback)
|
73
95
|
@on_change_callbacks << callback
|
74
96
|
end
|
97
|
+
deprecate on_change: :when_updated, deprecator: OnChangeDeprecation
|
75
98
|
|
76
99
|
# Assigns a new static context. Recomputes statically_targeted_settings.
|
77
100
|
# Keys must be strings or integers. No symbols.
|
@@ -128,7 +151,7 @@ module ProcessSettings
|
|
128
151
|
|
129
152
|
# Loads the latest untargeted settings from disk. Returns the current process settings as a TargetAndProcessSettings given
|
130
153
|
# by applying the static context to the current untargeted settings from disk.
|
131
|
-
# If these have changed, borrows this thread to call notify_on_change.
|
154
|
+
# If these have changed, borrows this thread to call notify_on_change and call_when_updated_blocks.
|
132
155
|
def load_statically_targeted_settings(force_retarget: false)
|
133
156
|
if force_retarget || @last_untargetted_settings != @untargeted_settings
|
134
157
|
@last_untargetted_settings = @untargeted_settings
|
@@ -137,6 +160,7 @@ module ProcessSettings
|
|
137
160
|
@last_statically_targetted_settings = @statically_targeted_settings
|
138
161
|
|
139
162
|
notify_on_change
|
163
|
+
call_when_updated_blocks
|
140
164
|
end
|
141
165
|
end
|
142
166
|
end
|
@@ -151,9 +175,11 @@ module ProcessSettings
|
|
151
175
|
end
|
152
176
|
|
153
177
|
def instance
|
154
|
-
|
155
|
-
|
156
|
-
|
178
|
+
@instance ||= begin
|
179
|
+
file_path or raise ArgumentError, "#{self}::file_path must be set before calling instance method"
|
180
|
+
logger or raise ArgumentError, "#{self}::logger must be set before calling instance method"
|
181
|
+
new(file_path, logger: logger)
|
182
|
+
end
|
157
183
|
end
|
158
184
|
|
159
185
|
def logger=(new_logger)
|
@@ -189,6 +215,14 @@ module ProcessSettings
|
|
189
215
|
end
|
190
216
|
end
|
191
217
|
|
218
|
+
def call_when_updated_blocks
|
219
|
+
@when_updated_blocks.each do |block|
|
220
|
+
block.call(self)
|
221
|
+
rescue => ex
|
222
|
+
logger.error("ProcessSettings::Monitor#call_when_updated_blocks rescued exception:\n#{ex.class}: #{ex.message}")
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
192
226
|
def load_file(file_path)
|
193
227
|
TargetedSettings.from_file(file_path)
|
194
228
|
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.
|
4
|
+
version: 0.7.0.pre.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Invoca
|
@@ -98,9 +98,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
98
98
|
version: '0'
|
99
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - ">"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: 1.3.1
|
104
104
|
requirements: []
|
105
105
|
rubygems_version: 3.0.3
|
106
106
|
signing_key:
|