class ServiceDowntimeSimulator::Config
Constants
- OPTIONS
- WonkyInputError
Attributes
logger[R]
Public Class Methods
for(config)
click to toggle source
# File lib/service_downtime_simulator/config.rb, line 14 def self.for(config) return config if config.is_a?(self) new(config) end
new(config_hash)
click to toggle source
# File lib/service_downtime_simulator/config.rb, line 20 def initialize(config_hash) raise WonkyInputError unless config_hash.is_a?(Hash) config_hash.each do |key, value| instance_variable_set("@#{key}", value) end end
Public Instance Methods
activated?()
click to toggle source
# File lib/service_downtime_simulator/config.rb, line 28 def activated? enabled == true && !mode.nil? end
enabled()
click to toggle source
# File lib/service_downtime_simulator/config.rb, line 32 def enabled @enabled == true end
excluded_paths()
click to toggle source
# File lib/service_downtime_simulator/config.rb, line 59 def excluded_paths if @excluded_paths.nil? moan(:excluded_paths, 'No excluded paths set. What about your health check endpoint?') return [] end unless @excluded_paths.is_a?(Array) moan(:excluded_paths, 'Excluded paths must ba an array of paths') return [] end # Detect if any elements are not a string if @excluded_paths.any? { |el| !el.is_a?(String) } moan(:excluded_paths, 'Excluded paths includes non-string value') return [] end @excluded_paths end
mode()
click to toggle source
# File lib/service_downtime_simulator/config.rb, line 36 def mode if @mode.nil? moan(:mode, 'No mode provided') return nil end unless @mode.is_a?(Symbol) moan(:mode, 'Mode must be a symbol') return nil end unless ServiceDowntimeSimulator::Modes.exists?(@mode) moan(:mode, "Unknown mode #{@mode}") return nil end @mode end
mode_klass()
click to toggle source
# File lib/service_downtime_simulator/config.rb, line 55 def mode_klass ServiceDowntimeSimulator::Modes.for(mode) end
path_excluded?(path)
click to toggle source
# File lib/service_downtime_simulator/config.rb, line 79 def path_excluded?(path) excluded_paths.include?(path) end
Private Instance Methods
moan(option, message)
click to toggle source
# File lib/service_downtime_simulator/config.rb, line 85 def moan(option, message) return unless logger.respond_to?(:error) logger.error("[SDS] Issue with #{option}: #{message}. Will not activate unless fixed.") end