Sha256: 3324f718c13aef2410fa949979b9317497c1b4d0cf532b25989b2ba93debb2b4

Contents?: true

Size: 1.15 KB

Versions: 10

Compression:

Stored size: 1.15 KB

Contents

module Cfer
  class Config < BlockHash
    def initialize(file = nil, options = nil, &block)
      @config_file = file
      deep_merge! options if options
      instance_eval &block if block
    end

    def method_missing(method_sym, *arguments, &block)
      key = camelize_property(method_sym)
      case arguments.size
      when 0
        if block
          Config.new(@config_file, nil, &block)
        else
          val = self[key]
          val =
            case val
            when Hash, nil
              Config.new(nil, val)
            else
              val
            end
          properties key => val
          val
        end
      else
        super
      end
    end

    # Includes config code from one or more files, and evals it in the context of this stack.
    # Filenames are relative to the file containing the invocation of this method.
    def include_config(*files)
      include_base = File.dirname(@config_file) if @config_file
      files.each do |file|
        path = File.join(include_base, file) if include_base
        include_file(path || file)
      end
    end

    private
    def non_proxied_methods
      []
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
cfer-1.0.0 lib/cfer/config.rb
cfer-0.8.0 lib/cfer/config.rb
cfer-0.7.0 lib/cfer/config.rb
cfer-0.6.2 lib/cfer/config.rb
cfer-0.6.1 lib/cfer/config.rb
cfer-0.6.0 lib/cfer/config.rb
cfer-0.5.0 lib/cfer/config.rb
cfer-0.5.0.pre.rc4 lib/cfer/config.rb
cfer-0.5.0.pre.rc3 lib/cfer/config.rb
cfer-0.5.0.pre.rc2 lib/cfer/config.rb