lib/one_apm/configuration.rb in oneapm_rpm-1.2.0 vs lib/one_apm/configuration.rb in oneapm_rpm-1.2.1.rc
- old
+ new
@@ -84,29 +84,40 @@
reset_cache
invoke_callbacks(:remove, source)
log_config(:remove, source)
end
- def replace_or_add_config(source)
+ def replace_or_add_config source
+ configure(source) do
+ invoke_callbacks(:add, source)
+ :add
+ end
+ end
+
+ def update_config source
+ configure(source) do
+ _invoke_callbacks_(source)
+ :update
+ end
+ end
+
+ def configure source
source.freeze
was_finished = finished_configuring?
-
- invoke_callbacks(:add, source)
+ operation = yield
case source
when HighSecuritySource then @high_security_source = source
when EnvironmentSource then @environment_source = source
when ServerSource then @server_source = source
when ManualSource then @manual_source = source
when YamlSource then @yaml_source = source
when DefaultSource then @default_source = source
else
OneApm::Manager.logger.warn("Invalid config format; config will be ignored: #{source}")
end
-
reset_cache
- log_config(:add, source)
-
+ log_config(operation, source)
notify_finished_configuring if !was_finished && finished_configuring?
end
def source(key)
config_stack.each do |config|
@@ -163,23 +174,42 @@
def register_callback(key, &proc)
@callbacks[key] << proc
proc.call(@cache[key])
end
- def invoke_callbacks(direction, source)
+ def _invoke_callbacks_ source
return unless source
+ @directions = directions(source)
source.keys.each do |key|
+ _callbacks_(@directions[key], source, key)
+ end
+ end
- if @cache[key] != source[key]
- @callbacks[key].each do |proc|
- if direction == :add
- proc.call(source[key])
- else
- proc.call(@cache[key])
- end
+ def invoke_callbacks direction, source
+ return unless source
+ source.keys.each do |key|
+ _callbacks_(direction, source, key)
+ end
+ end
+
+ def _callbacks_ direction, source, key
+ if @cache[key] != source[key]
+ @callbacks[key].each do |proc|
+ case direction
+ when :add then proc.call(source[key])
+ when :append then proc.call(@cache[key], source[key])
+ else proc.call(@cache[key])
end
end
end
+ end
+
+ def directions source
+ h = Hash.new{|h, k| h[k] = :add}
+ source.each do |key, value|
+ h[key] = source[:"#{key}.direction"].to_sym if source[:"#{key}.direction"]
+ end
+ h
end
def notify_finished_configuring
OneApm::Manager.agent.events.notify(:finished_configuring)
end