Class: Mysticonfig::Loader

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

Overview

Configuration loader.

Instance Method Summary collapse

Constructor Details

#initialize(appname) ⇒ Loader

Returns a new instance of Loader.



9
10
11
# File 'lib/mysticonfig.rb', line 9

def initialize(appname)
  @filenames = Utils.generate_config_filenames appname
end

Instance Method Details

#loadObject

Find and load config file.



15
16
17
18
19
# File 'lib/mysticonfig.rb', line 15

def load
  config_file = find_file @filenames

  Utils.load_auto config_file
end

#load_jsonObject

Find and load JSON config file.



23
24
25
26
27
# File 'lib/mysticonfig.rb', line 23

def load_json
  json_config_file = Utils.lookup_file @filenames[:json]

  Utils.load_json json_config_file
end

#load_yamlObject

Find and load YAML config file.



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/mysticonfig.rb', line 31

def load_yaml
  yaml_config_files = @filenames[:yaml]
  yaml_config_file = nil

  yaml_config_files.each do |file|
    yaml_config_file = Utils.lookup_file file
    return Utils.load_yaml(yaml_config_file) unless yaml_config_file.nil?
  end

  {} # Return empty hash when can't load config file
end