Class: ProcessSettings::Testing::MonitorStub

Inherits:
Object
  • Object
show all
Defined in:
lib/process_settings/testing/monitor_stub.rb

Overview

This class implements the Monitor#targeted_value interface but is stubbed to use a simple hash in tests

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings_hash) ⇒ MonitorStub

Returns a new instance of MonitorStub.



21
22
23
# File 'lib/process_settings/testing/monitor_stub.rb', line 21

def initialize(settings_hash)
  @settings_hash = HashWithHashPath[settings_hash]
end

Class Method Details

.new(*_args) ⇒ Object



15
16
17
18
# File 'lib/process_settings/testing/monitor_stub.rb', line 15

def new(*_args)
  ActiveSupport::Deprecation.warn("ProcessSettings::Testing::MonitorStub is deprecated and will be removed in future versions. Use ProcessSettings::Testing::Monitor instead.", caller)
  super
end

Instance Method Details

#[](*path, dynamic_context: {}, required: true) ⇒ Object



25
26
27
# File 'lib/process_settings/testing/monitor_stub.rb', line 25

def [](*path, dynamic_context: {}, required: true)
  targeted_value(*path, dynamic_context: dynamic_context, required: required)
end

#targeted_value(*path, dynamic_context:, required: true) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/process_settings/testing/monitor_stub.rb', line 29

def targeted_value(*path, dynamic_context:, required: true)
  result = @settings_hash.mine(*path, not_found_value: :not_found)

  if result == :not_found
    if required
      raise SettingsPathNotFound, "no settings found for path #{path.inspect}"
    else
      nil
    end
  else
    result
  end
end