Class: Mysticonfig::Loader
- Inherits:
-
Object
- Object
- Mysticonfig::Loader
- Defined in:
- lib/mysticonfig.rb
Overview
Configuration loader.
Instance Method Summary collapse
-
#initialize(appname, default_config = {}) ⇒ Loader
constructor
A new instance of Loader.
-
#load ⇒ Object
Find and load config file.
-
#load_json ⇒ Object
Find and load JSON config file.
-
#load_yaml ⇒ Object
Find and load YAML config file.
Constructor Details
#initialize(appname, default_config = {}) ⇒ Loader
Returns a new instance of Loader.
9 10 11 12 |
# File 'lib/mysticonfig.rb', line 9 def initialize(appname, default_config = {}) @filenames = Utils.generate_config_filenames appname @default_config = default_config end |
Instance Method Details
#load ⇒ Object
Find and load config file.
16 17 18 19 20 21 |
# File 'lib/mysticonfig.rb', line 16 def load config_file = find_file @filenames config = Utils.load_auto config_file config.empty? ? @default_config : @default_config.merge(config) end |
#load_json ⇒ Object
Find and load JSON config file.
25 26 27 28 29 30 |
# File 'lib/mysticonfig.rb', line 25 def load_json json_config_file = Utils.lookup_file @filenames[:json] config = Utils.load_json json_config_file config.empty? ? @default_config : @default_config.merge(config) end |
#load_yaml ⇒ Object
Find and load YAML config file.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/mysticonfig.rb', line 34 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 unless yaml_config_file.nil? config = Utils.load_yaml(yaml_config_file) return config.empty? ? @default_config : @default_config.merge(config) end end @default_config # Return default config when can't load config file end |