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-6.0.0 lib/bookends/config.rb
bookends-6.0.0.rc3 lib/bookends/config.rb
bookends-6.0.0.rc2 lib/bookends/config.rb
bookends-6.0.0.rc1 lib/bookends/config.rb
bookends-5.0.0 lib/bookends/config.rb
bookends-4.2.9 lib/bookends/config.rb
bookends-4.2.8 lib/bookends/config.rb
bookends-4.2.7 lib/bookends/config.rb
bookends-4.2.7rc1 lib/bookends/config.rb
bookends-4.2.6 lib/bookends/config.rb
bookends-4.2.6rc1 lib/bookends/config.rb
bookends-4.2.5 lib/bookends/config.rb
bookends-4.2.4 lib/bookends/config.rb
bookends-4.2.3 lib/bookends/config.rb
bookends-4.2.2 lib/bookends/config.rb
bookends-4.2.1 lib/bookends/config.rb
bookends-4.2.1rc1 lib/bookends/config.rb
bookends-4.1.1 lib/bookends/config.rb
bookends-4.1.1rc1 lib/bookends/config.rb
bookends-4.2.0beta1 lib/bookends/config.rb