Sha256: 5643620682c9905b32121cbc934919292795830196026ba4f95a364dbf1e5aa5

Contents?: true

Size: 804 Bytes

Versions: 2

Compression:

Stored size: 804 Bytes

Contents

require 'hashie/extensions/method_access'
require 'hashie/extensions/coercion'

module Cupcakinator

  # known configuration variables
  # method
  # dir
  # file
  # root_key
  # allow_missing
  class Config < Hash
    include Hashie::Extensions::MethodAccess
    include Hashie::Extensions::Coercion

    coerce_value Hash, Config

    # @param [Hash] h
    # @return Cupcakinator::Config
    def initialize(h={})
      super
      h.each_pair do |k,v|
        self[k] = v
      end
    end


    # @return [Hash] returns uncoerced Hash
    def to_h
      convert_config_to_hash(self.dup)
    end


    private


    def convert_config_to_hash(c)
      h = Hash.new
      c.each_pair{ |key, value| Config === value ? h[key] = convert_config_to_hash(value) : h[key] = value }
      h
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cupcakinator-1.1.2 lib/cupcakinator/config.rb
cupcakinator-1.1.1 lib/cupcakinator/config.rb