Class: Kuromd::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/kuromd/config.rb

Overview

Handles pulling the configuration from a configuration file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Config

Returns a new instance of Config.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/kuromd/config.rb', line 28

def initialize(params = {})
  Dotenv.load

  @config_filepath = File.join(configuration_folder, configuration_file)
  @config_filepath = params[:config_file] unless params[:config_file].nil?
  config_file = File.expand_path(@config_filepath)
  # Kuromd.logger.info "Configuration file: #{config_file}"

  # replace the configuration with what was passed
  @params = {}
  @params = YAML.load(File.read(config_file)) if File.exist?(config_file)

  # assume production unless otherwise specified
  @params['environment'] = 'production'
  unless ENV['ENVIRONMENT'].nil?
    @params['environment'] = ENV['ENVIRONMENT']
  end

  Kuromd.logger.info "Configuration initialized: #{config_file}" unless @params.nil?
end

Instance Attribute Details

#config_filepathObject

Returns the value of attribute config_filepath.



10
11
12
# File 'lib/kuromd/config.rb', line 10

def config_filepath
  @config_filepath
end

#paramsObject

Returns the value of attribute params.



10
11
12
# File 'lib/kuromd/config.rb', line 10

def params
  @params
end

Instance Method Details

#configuration_fileObject



16
17
18
# File 'lib/kuromd/config.rb', line 16

def configuration_file
  'configuration.yml'
end

#configuration_folderObject



12
13
14
# File 'lib/kuromd/config.rb', line 12

def configuration_folder
  '~/.config/kuromd'
end

#get_config(key) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/kuromd/config.rb', line 20

def get_config(key)
  if key.nil?
    @params
  else
    @params[key]
  end
end