Class: Puppet::Pops::Containment::EAllContentsEnumerator Private

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/puppet/pops/containment.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(o) ⇒ EAllContentsEnumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of EAllContentsEnumerator.



44
45
46
47
# File 'lib/puppet/pops/containment.rb', line 44

def initialize o
  @element = o
  @@cache ||= {}
end

Instance Method Details

#each(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



49
50
51
52
53
54
55
56
# File 'lib/puppet/pops/containment.rb', line 49

def each &block
  if block_given?
    eAllContents(@element, &block)
    @element
  else
    self
  end
end

#eAllContents(element, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/puppet/pops/containment.rb', line 58

def eAllContents(element, &block)
  # This method is performance critical and code has been manually in-lined.
  # Resist the urge to make this pretty.
  # The slow way is element.eAllContainments.each {|c| element.getGenericsAsArray(c.name) }
  #
  (@@cache[element.class] || all_containment_getters(element)).each do |r|
    children = element.send(r)
    if children.is_a?(Array)
      children.each do |c|
        yield c
        eAllContents(c, &block)
      end
    elsif !children.nil?
      yield children
      eAllContents(children, &block)
    end
  end
end