Class: Kuromd::Config
- Inherits:
-
Object
- Object
- Kuromd::Config
- Defined in:
- lib/kuromd/config.rb
Overview
Handles pulling the configuration from a configuration file.
Instance Attribute Summary collapse
-
#config_filepath ⇒ Object
Returns the value of attribute config_filepath.
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
- #configuration_file ⇒ Object
- #configuration_folder ⇒ Object
- #get_config(key) ⇒ Object
-
#initialize(params = {}) ⇒ Config
constructor
A new instance of Config.
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.(@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_filepath ⇒ Object
Returns the value of attribute config_filepath.
10 11 12 |
# File 'lib/kuromd/config.rb', line 10 def config_filepath @config_filepath end |
#params ⇒ Object
Returns the value of attribute params.
10 11 12 |
# File 'lib/kuromd/config.rb', line 10 def params @params end |
Instance Method Details
#configuration_file ⇒ Object
16 17 18 |
# File 'lib/kuromd/config.rb', line 16 def configuration_file 'configuration.yml' end |
#configuration_folder ⇒ Object
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 |