Class: By2::ConfigLoader

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfigLoader

Returns a new instance of ConfigLoader.



5
6
7
# File 'lib/by2/config_loader.rb', line 5

def initialize
  @search_paths ||= [app_config, user_config]
end

Instance Attribute Details

#search_pathsObject

Returns the value of attribute search_paths.



3
4
5
# File 'lib/by2/config_loader.rb', line 3

def search_paths
  @search_paths
end

Instance Method Details

#load(config_file, required = false) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/by2/config_loader.rb', line 9

def load(config_file, required = false)
  search_paths.each do |path|
    file = File.expand_path(File.join(path, config_file))
    By2.debug("Searching for #{file} in #{path}")

    if File.exists?(file)
      By2.debug("Loaded: #{file}")
      return YAML.load_file(file)
    end
  end

  By2.debug("Could not load: #{config_file}")
  required ? raise : nil
end