Sha256: 4f160cff1e88677613e9cc67786287c2f1cbe188c87831843d5af6f6dc2ac7e3

Contents?: true

Size: 754 Bytes

Versions: 115

Compression:

Stored size: 754 Bytes

Contents

module Bookends
  module Config
    extend self

    @_config = {}
    attr_reader :_config

    def load!(filename, options = {})
      configs = YAML::load_file(filename).deep_symbolize_keys
      configs = configs[options[:env].to_sym] if options[:env] && configs[options[:env].to_sym]
      deep_merge!(@_config, configs)
    end

    # deep_merge by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809
    def deep_merge!(target, data)
      merger = proc{ |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
      target.merge! data, &merger
    end

    def method_missing(name, *args, &block)
      @_config[name.to_sym] || fail(NoMethodError, "Calling undefined Bookends config: #{name}", caller)
    end
  end
end

Version data entries

115 entries across 115 versions & 1 rubygems

Version Path
bookends-10.3.4 lib/bookends/config.rb
bookends-10.3.3 lib/bookends/config.rb
bookends-10.3.2 lib/bookends/config.rb
bookends-10.3.1 lib/bookends/config.rb
bookends-10.3.0 lib/bookends/config.rb
bookends-10.2.8 lib/bookends/config.rb
bookends-10.2.7 lib/bookends/config.rb
bookends-10.2.6 lib/bookends/config.rb
bookends-10.2.5 lib/bookends/config.rb
bookends-10.2.5.alpha8 lib/bookends/config.rb
bookends-10.2.5.alpha7 lib/bookends/config.rb
bookends-10.2.5.alpha6 lib/bookends/config.rb
bookends-10.2.5.alpha5 lib/bookends/config.rb
bookends-10.2.5.alpha4 lib/bookends/config.rb
bookends-10.2.5.alpha3 lib/bookends/config.rb
bookends-10.2.5.alpha2 lib/bookends/config.rb
bookends-10.2.5.alpha lib/bookends/config.rb
bookends-10.2.4 lib/bookends/config.rb
bookends-10.2.3 lib/bookends/config.rb
bookends-10.2.1 lib/bookends/config.rb