Sha256: 6d29cdfa83154f0df9923e256776d27811fdcebc3aa15530d0f03989621a7ffb

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

require 'yaml'
require 'devinstall/deep_symbolize'

module Settings
  extend self

  @_settings = {}
  attr_reader :_settings

  def load!(filename, options = {})
    unless File.exist?(filename)
      puts "Unable to find config file \"#{filename}\""
      exit!(1)
    end
    newsets = YAML::load_file(filename).deep_symbolize
    newsets = newsets[options[:env].to_sym] if options[:env] && newsets[options[:env].to_sym]
    deep_merge!(@_settings, newsets)
  end

  def deep_merge!(target, data)
    merger = proc { |_, v1, v2|
      Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
    target.merge! data, &merger
  end

  #def method_missing(name, *args, &block)
  #  @_settings[name.to_sym] ||
  #      fail(NoMethodError, "unknown configuration root #{name}", caller)
  #end

  def base
    @_settings[:base]
  end

  def local
    @_settings[:local]
  end

  def build
    @_settings[:build]
  end

  def install
    @_settings[:install]
  end

  def repos
    @_settings[:repos]
  end

  def packages
    @_settings[:packages]
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
devinstall-0.0.6 lib/devinstall/settings.rb