Class: ConfigMapper::ConfigList

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

Defined Under Namespace

Classes: Factory

Instance Method Summary collapse

Constructor Details

#initialize(entry_factory) ⇒ ConfigList

Returns a new instance of ConfigList.



33
34
35
36
# File 'lib/config_mapper/config_list.rb', line 33

def initialize(entry_factory)
  @entry_factory = entry_factory
  @entries = []
end

Instance Method Details

#[](index) ⇒ Object



38
39
40
# File 'lib/config_mapper/config_list.rb', line 38

def [](index)
  @entries[index] ||= @entry_factory.new
end

#config_errorsObject



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/config_mapper/config_list.rb', line 52

def config_errors
  {}.tap do |errors|
    each_with_index do |element, index|
      next unless element.respond_to?(:config_errors)
      prefix = "[#{index}]"
      element.config_errors.each do |path, path_errors|
        errors["#{prefix}#{path}"] = path_errors
      end
    end
  end
end

#to_aObject



42
43
44
45
46
47
48
49
50
# File 'lib/config_mapper/config_list.rb', line 42

def to_a
  map do |element|
    case
      when element.respond_to?(:to_h); element.to_h
      when element.respond_to?(:to_a); element.to_a
      else element
    end
  end
end