class ScoutApm::Config
Constants
- KNOWN_CONFIG_OPTIONS
- SETTING_COERCIONS
Public Class Methods
Source
# File lib/scout_apm/config.rb, line 259 def initialize(context, overlays) @context = context @overlays = Array(overlays) end
Source
# File lib/scout_apm/config.rb, line 249 def self.with_file(context, file_path=nil, config={}) overlays = [ ConfigEnvironment.new, ConfigFile.new(context, file_path, config), ConfigDefaults.new, ConfigNull.new, ] new(context, overlays) end
Load up a config instance, attempting to load a yaml file. Allows a definite location if requested, or will attempt to load the default configuration file: APP_ROOT/config/scout_apm.yml
Source
# File lib/scout_apm/config.rb, line 237 def self.without_file(context) overlays = [ ConfigEnvironment.new, ConfigDefaults.new, ConfigNull.new, ] new(context, overlays) end
Load up a config instance without attempting to load a file. Useful for bootstrapping.
Public Instance Methods
Source
# File lib/scout_apm/config.rb, line 294 def all_settings KNOWN_CONFIG_OPTIONS.inject([]) do |memo, key| o = overlay_for_key(key) memo << {:key => key, :value => value(key).inspect, :source => o.name} end end
Returns an array of config keys, values, and source {key: “monitor”, value: “true”, source: “environment”}
Source
# File lib/scout_apm/config.rb, line 287 def any_keys_found? @overlays.any? { |overlay| overlay.any_keys_found? } end
Did we load anything for configuration?
Source
# File lib/scout_apm/config.rb, line 301 def log_settings(logger) logger.debug( "Resolved Setting Values:\n" + all_settings.map{|hsh| "#{hsh[:source]} - #{hsh[:key]}: #{hsh[:value]}"}.join("\n") ) end
Source
# File lib/scout_apm/config.rb, line 265 def overlay_for_key(key) @overlays.detect{ |overlay| overlay.has_key?(key) } end
For a given key, what is the first overlay says that it can handle it?
Source
# File lib/scout_apm/config.rb, line 269 def value(key) if ! KNOWN_CONFIG_OPTIONS.include?(key) logger.debug("Requested looking up a unknown configuration key: #{key} (not a problem. Evaluate and add to config.rb)") end o = overlay_for_key(key) raw_value = if o o.value(key) else # No overlay said it could handle this key, bail out with nil. nil end coercion = SETTING_COERCIONS.fetch(key, NullCoercion.new) coercion.coerce(raw_value) end