Sha256: 8dbf2acc6e745c4078d6df90ea436ef8604d42bd7f703f004ce9dc326880db71
Contents?: true
Size: 1.14 KB
Versions: 3
Compression:
Stored size: 1.14 KB
Contents
# frozen_string_literal: true require 'active_support/core_ext/hash/deep_merge' require 'forwardable' require 'pathname' require 'singleton' require 'yaml' require_relative 'config/config_helper' # Global config wrapper module Core # configuration wrapper class Config include Singleton include ConfigHelper attr_reader :config_name def initialize @config_name = ENV['SA_ENV'] ||= 'local' @config = {} ['base', @config_name].each do |name| f = Pathname.new(CONFIG_DIR).join("#{name}.yml") c = YAML.load_file(f) next unless c @config.deep_merge!(c) rescue StandardError => e STDERR.puts "Error reading config file #{e}" raise end end def key?(key) ENV.key?(key) || @config.key?(key) end def [](key) ENV.key?(key) ? ENV[key] : @config[key] end # forward class method calls to the instance so we can do Config['VARNAME'] or Config.get_i!(:FOO) class << self extend Forwardable def_delegators :instance, *Config.instance_methods(false), *ConfigHelper.instance_methods(false) end end end Core::Config.instance
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
svcbase-0.1.18 | lib/svcbase/config.rb |
svcbase-0.1.17 | lib/svcbase/config.rb |
svcbase-0.1.16 | lib/svcbase/config.rb |