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

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

Instance Method Summary collapse

Constructor Details

#initialize(o) ⇒ EAllContentsEnumerator

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



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



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