class ScoutApm::Config::ConfigFile
Attempts to load a configuration file, and parse it as YAML. If the file is not found, inaccessbile, or unparsable, log a message to that effect, and move on.
Attributes
context[R]
Public Class Methods
new(context, file_path=nil, config={})
click to toggle source
# File lib/scout_apm/config.rb, line 384 def initialize(context, file_path=nil, config={}) @context = context @config = config || {} @resolved_file_path = file_path || determine_file_path load_file(@resolved_file_path) end
Public Instance Methods
any_keys_found?()
click to toggle source
# File lib/scout_apm/config.rb, line 404 def any_keys_found? KNOWN_CONFIG_OPTIONS.any? { |option| @settings.has_key?(option) } end
has_key?(key)
click to toggle source
# File lib/scout_apm/config.rb, line 400 def has_key?(key) @settings.has_key?(key) end
name()
click to toggle source
# File lib/scout_apm/config.rb, line 410 def name "config-file" end
value(key)
click to toggle source
# File lib/scout_apm/config.rb, line 391 def value(key) if @file_loaded val = @settings[key] val.to_s.strip.length.zero? ? nil : val else nil end end
Private Instance Methods
app_environment()
click to toggle source
# File lib/scout_apm/config.rb, line 456 def app_environment @config[:environment] || context.environment.env end
determine_file_path()
click to toggle source
# File lib/scout_apm/config.rb, line 452 def determine_file_path File.join(context.environment.root, "config", "scout_apm.yml") end
load_file(file)
click to toggle source
# File lib/scout_apm/config.rb, line 418 def load_file(file) @settings = {} if !File.exist?(@resolved_file_path) logger.debug("Configuration file #{file} does not exist, skipping.") @file_loaded = false return end if !app_environment logger.debug("Could not determine application environment, aborting configuration file load") @file_loaded = false return end begin raw_file = File.read(@resolved_file_path) erb_file = ERB.new(raw_file).result(binding) parsed_yaml = YAML.load(erb_file) file_settings = parsed_yaml[app_environment] if file_settings.is_a? Hash logger.debug("Loaded Configuration: #{@resolved_file_path}. Using environment: #{app_environment}") @settings = file_settings @file_loaded = true else logger.info("Couldn't find configuration in #{@resolved_file_path} for environment: #{app_environment}. Configuration in ENV will still be applied.") @file_loaded = false end rescue Exception => e # Explicit `Exception` handling to catch SyntaxError and anything else that ERB or YAML may throw logger.info("Failed loading configuration file (#{@resolved_file_path}): #{e.message}. ScoutAPM will continue starting with configuration from ENV and defaults") @file_loaded = false end end
logger()
click to toggle source
# File lib/scout_apm/config.rb, line 460 def logger context.logger end