Class: Configru::Config

Inherits:
StructHash show all
Defined in:
lib/configru/config.rb

Instance Method Summary collapse

Methods inherited from StructHash

#method_missing

Constructor Details

#initialize(*files, &block) ⇒ Config

Returns a new instance of Config.



7
8
9
10
11
# File 'lib/configru/config.rb', line 7

def initialize(*files, &block)
  @files = files.flatten
  @dsl_block = block
  reload
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Configru::StructHash

Instance Method Details

#reloadObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/configru/config.rb', line 13

def reload
  @options = DSL::OptionGroup.new(&@dsl_block).options

  loaded_files = Array.new
  @files.each do |file|
    if File.file?(file) && !File.zero?(file)
      load_file(file)
      loaded_files << file
    end
  end

  # Load all defaults if no files were loaded
  # TODO: Some way to not special case this
  @option_path = Array.new
  @file = '(none)'
  load_group(@options, self, {}) if loaded_files.empty?
end