33 lines
626 B
Ruby
33 lines
626 B
Ruby
# frozen_string_literal: true
|
|
|
|
require 'yaml'
|
|
|
|
# Configuration loader - loads config defaults and an optional config file
|
|
class Config
|
|
|
|
DEFAULT_CONFIG = 'config/defaults.yaml'
|
|
|
|
def initialize(config_path)
|
|
# Load the default config
|
|
@data = YAML.load_file(DEFAULT_CONFIG)
|
|
|
|
# End if the optional config file doesn't exist
|
|
return unless File.exist?(config_path)
|
|
|
|
# If the optional config exists, load it up!
|
|
@data.merge!(YAML.load_file(config_path))
|
|
end
|
|
|
|
def get(key)
|
|
bits = key.split('.')
|
|
value = @data
|
|
|
|
bits.each do |bit|
|
|
value = value[bit]
|
|
end
|
|
|
|
return value
|
|
end
|
|
|
|
end
|