Class: ConfigMapper::ConfigDict

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/config_mapper/config_dict.rb

Instance Method Summary collapse

Constructor Details

#initialize(entry_type, key_type = nil) ⇒ ConfigDict



7
8
9
10
11
# File 'lib/config_mapper/config_dict.rb', line 7

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

Instance Method Details

#[](key) ⇒ Object



13
14
15
16
# File 'lib/config_mapper/config_dict.rb', line 13

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

#to_hObject



18
19
20
21
22
23
24
# File 'lib/config_mapper/config_dict.rb', line 18

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