Class: Core::Config

Inherits:
Object show all
Extended by:
Forwardable
Includes:
ConfigHelper, Singleton
Defined in:
lib/svcbase/config.rb

Overview

configuration wrapper

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ConfigHelper

#get_b!, #get_f!, #get_i!, #get_s!, #get_x!

Constructor Details

#initializeConfig

Returns a new instance of Config.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/svcbase/config.rb', line 20

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

Instance Attribute Details

#config_nameObject (readonly)

Returns the value of attribute config_name.



18
19
20
# File 'lib/svcbase/config.rb', line 18

def config_name
  @config_name
end

Instance Method Details

#[](key) ⇒ Object



38
39
40
# File 'lib/svcbase/config.rb', line 38

def [](key)
  ENV.key?(key) ? ENV[key] : @config[key]
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/svcbase/config.rb', line 34

def key?(key)
  ENV.key?(key) || @config.key?(key)
end