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.



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

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

Instance Method Details

#[](index) ⇒ Object



41
42
43
# File 'lib/config_mapper/config_list.rb', line 41

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

#config_errorsObject



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

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



45
46
47
48
49
50
51
52
# File 'lib/config_mapper/config_list.rb', line 45

def to_a
  map do |element|
    if element.respond_to?(:to_h) then element.to_h
    elsif element.respond_to?(:to_a) then element.to_a
    else element
    end
  end
end