Sha256: d3ccc8b8e061a43a845b3a7ddeba84bed61658a9b590400275d04fafbfd310ad

Contents?: true

Size: 1.03 KB

Versions: 2

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

2 entries across 2 versions & 1 rubygems

Version Path
devinstall-0.0.5 lib/devinstall/settings.rb
devinstall-0.0.4 lib/devinstall/settings.rb