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
Public Class Methods
Source
# File lib/scout_apm/config.rb, line 427 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
Source
# File lib/scout_apm/config.rb, line 447 def any_keys_found? KNOWN_CONFIG_OPTIONS.any? { |option| @settings.has_key?(option) } end
Source
# File lib/scout_apm/config.rb, line 443 def has_key?(key) @settings.has_key?(key) end
Source
# File lib/scout_apm/config.rb, line 434 def value(key) if @file_loaded val = @settings[key] val.to_s.strip.length.zero? ? nil : val else nil end end
Private Instance Methods
Source
# File lib/scout_apm/config.rb, line 499 def app_environment @config[:environment] || context.environment.env end
Source
# File lib/scout_apm/config.rb, line 495 def determine_file_path File.join(context.environment.root, "config", "scout_apm.yml") end
Source
# File lib/scout_apm/config.rb, line 461 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.respond_to?(:unsafe_load) ? YAML.unsafe_load(erb_file) : 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 ScoutApm::AllExceptionsExceptOnesWeMustNotRescue => e # Everything except the most important exceptions we should never interfere with logger.info("Failed loading configuration file (#{@resolved_file_path}): ScoutAPM will continue starting with configuration from ENV and defaults. Exception was #{e.class}: #{e.message}#{e.backtrace.map { |bt| "\n #{bt}" }.join('')}") @file_loaded = false end end