av-ast/configus2

View on GitHub
lib/configus2/proxy.rb

Summary

Maintainability
A
0 mins
Test Coverage
module Configus2
  class Proxy
    attr_reader :hash_data, :config

    def initialize(&block)
      @hash_data = {}
      instance_eval(&block)
    end

    def method_missing(method_sym, *arguments, &block)
      if block_given?
        p = Proxy.new(&block)
        @hash_data[method_sym] = p.hash_data
      else
        @hash_data[method_sym] = arguments.first
      end
    end

    def get_config
      config = Config.new(@hash_data)
      config.get
    end

    def merge_with_parent(parent)
      @hash_data = parent.to_hash.merge(@hash_data)
    end

  end
end