Sha256: f4acc5a2bcdb3029bf758a4c5d7aa6d0ad099f427a1c248efe72ca8758e4517f

Contents?: true

Size: 583 Bytes

Versions: 3

Compression:

Stored size: 583 Bytes

Contents

require "forwardable"

module ConfigMapper

  class ConfigDict

    def initialize(entry_type, key_type = nil)
      @entry_type = entry_type
      @key_type = key_type
      @entries = {}
    end

    def [](key)
      key = @key_type.call(key) if @key_type
      @entries[key] ||= @entry_type.call
    end

    def to_h
      {}.tap do |result|
        @entries.each do |key, value|
          result[key] = value.to_h
        end
      end
    end

    extend Forwardable

    def_delegators :@entries, :each, :empty?, :key?, :keys, :map, :size

    include Enumerable

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
config_mapper-1.4.1 lib/config_mapper/config_dict.rb
config_mapper-1.3.1 lib/config_mapper/config_dict.rb
config_mapper-1.3.0 lib/config_mapper/config_dict.rb