class ConfigPlus::Loader

Attributes

config[R]

Public Class Methods

new(config) click to toggle source
# File lib/config_plus/loader.rb, line 3
def initialize(config)
  @config = config
end

Public Instance Methods

load() click to toggle source
# File lib/config_plus/loader.rb, line 7
def load
  paths = source_paths
  raise "No specified `source'" if paths.empty?

  paths.inject({}) do |h, path|
    hsh = loader_logic.load_from(path)
    hsh = hsh[config.namespace.to_s] if config.namespace
    Merger.merge(h, hsh)
  end
end

Protected Instance Methods

loader_logic() click to toggle source
# File lib/config_plus/loader.rb, line 20
def loader_logic
  @loader_logic ||= config.loader_logic.new(config.extension)
end
source_path(filepath) click to toggle source
# File lib/config_plus/loader.rb, line 30
def source_path(filepath)
  return filepath unless config.root_dir
  return config.root_dir unless filepath
  return filepath if filepath.start_with?('/')
  File.join(config.root_dir, filepath)
end
source_paths() click to toggle source
# File lib/config_plus/loader.rb, line 24
def source_paths
  Array(config.source).map {|s|
    source_path(s)
  }.reverse.uniq.compact.reverse
end