Module: ConfigReader

Defined in:
lib/configreader.rb,
lib/configreader/config.rb,
lib/configreader/engine.rb,
lib/configreader/version.rb,
lib/configreader/env_configreader.rb,
lib/configreader/flat_configreader.rb,
lib/configreader/mixins/file_loading.rb

Defined Under Namespace

Modules: FileLoading Classes: Config, Engine, EnvConfigReader, FlatConfigReader

Constant Summary collapse

VERSION =
"0.0.4"

Class Method Summary collapse

Class Method Details

.build_config_filesObject



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

def self.build_config_files
  return unless config.auto_create_config_objects

  build_files(config.auto_create_config_folder, FlatConfigReader)
  build_files("#{config.auto_create_config_folder}/env", EnvConfigReader)
end

.build_files(folder, klass) ⇒ Object



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

def self.build_files(folder, klass)
  Dir["#{folder}/*.yml"].each do |file|
    path = Pathname.new(file)
    next if path.directory? or !path.exist?

    config.auto_create_class.class_eval do
      const_set(path.basename('.*').to_s.upcase, klass.new(YAML.load_file(file)))
    end
  end

end

.configObject



19
20
21
# File 'lib/configreader.rb', line 19

def self.config
  @config ||= ConfigReader::Config.default
end

.initialize(&block) ⇒ Object



12
13
14
15
16
17
# File 'lib/configreader.rb', line 12

def self.initialize(&block)
  return if ConfigReader.initialized
  ConfigReader.module_eval &block
  build_config_files
  ConfigReader.initialized = true
end