Method: Puppet::Pops::Types::Iterable.asserted_iterable

Defined in:
lib/puppet/pops/types/iterable.rb

.asserted_iterable(my_caller, obj, infer_elements = false) ⇒ Iterable?

Produces an ‘Iterable` for one of the following types with the following characterstics:

‘String` - yields each character in the string `Array` - yields each element in the array `Hash` - yields each key/value pair as a two element array `Integer` - when positive, yields each value from zero to the given number `PIntegerType` - yields each element from min to max (inclusive) provided min < max and neither is unbounded. `PEnumtype` - yields each possible value of the enum. `Range` - yields an iterator for all elements in the range provided that the range start and end

are both integers or both strings and start is less than end using natural ordering.

‘Dir` - yields each name in the directory

An ‘ArgumentError` is raised for all other objects.

Raises:

  • (ArgumentError)

    In case an ‘Iterable` cannot be produced



33
34
35
36
37
# File 'lib/puppet/pops/types/iterable.rb', line 33

def self.asserted_iterable(my_caller, obj, infer_elements = false)
  iter = self.on(obj, nil, infer_elements)
  raise ArgumentError, "#{my_caller.class}(): wrong argument type (#{obj.class}; is not Iterable." if iter.nil?
  iter
end