class ScoutApm::Config

Constants

KNOWN_CONFIG_OPTIONS
SETTING_COERCIONS

Public Class Methods

new(context, overlays) click to toggle source
# File lib/scout_apm/config.rb, line 226
def initialize(context, overlays)
  @context = context
  @overlays = Array(overlays)
end
with_file(context, file_path=nil, config={}) click to toggle source

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

# File lib/scout_apm/config.rb, line 216
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
without_file(context) click to toggle source

Load up a config instance without attempting to load a file. Useful for bootstrapping.

# File lib/scout_apm/config.rb, line 204
def self.without_file(context)
  overlays = [
    ConfigEnvironment.new,
    ConfigDefaults.new,
    ConfigNull.new,
  ]
  new(context, overlays)
end

Public Instance Methods

all_settings() click to toggle source

Returns an array of config keys, values, and source {key: “monitor”, value: “true”, source: “environment”}

# File lib/scout_apm/config.rb, line 261
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
any_keys_found?() click to toggle source

Did we load anything for configuration?

# File lib/scout_apm/config.rb, line 254
def any_keys_found?
  @overlays.any? { |overlay| overlay.any_keys_found? }
end
log_settings(logger) click to toggle source
# File lib/scout_apm/config.rb, line 268
def log_settings(logger)
  logger.debug(
    "Resolved Setting Values:\n" +
    all_settings.map{|hsh| "#{hsh[:source]} - #{hsh[:key]}: #{hsh[:value]}"}.join("\n")
  )
end
logger() click to toggle source
# File lib/scout_apm/config.rb, line 275
def logger
  @context.logger
end
overlay_for_key(key) click to toggle source

For a given key, what is the first overlay says that it can handle it?

# File lib/scout_apm/config.rb, line 232
def overlay_for_key(key)
  @overlays.detect{ |overlay| overlay.has_key?(key) }
end
value(key) click to toggle source
# File lib/scout_apm/config.rb, line 236
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