Sha256: 4ebbd0ad142f81c4878c523f5e1f68286ab028a204f628fc6a67562bec8efec3

Contents?: true

Size: 1022 Bytes

Versions: 22

Compression:

Stored size: 1022 Bytes

Contents

# FIXME: This module should be updated when a newer version of RGen (>0.6.2) adds required meta model "e-method" supports.
#
module Puppet::Pops::Containment
  # Returns Enumerable, thus allowing
  # some_element.eAllContents each {|contained| }
  # This is a depth first enumeration where parent appears before children.
  # @note the top-most object itself is not included in the enumeration, only what it contains.
  def eAllContents
    EAllContentsEnumerator.new(self)
  end

  class EAllContentsEnumerator
    include Enumerable
    def initialize o
      @element = o
    end

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

    def eAllContents(element, &block)
      element.class.ecore.eAllReferences.select{|r| r.containment}.each do |r|
        children = element.getGenericAsArray(r.name)
        children.each do |c|
          block.call(c)
          eAllContents(c, &block)
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
puppet-3.4.3 lib/puppet/pops/containment.rb
puppet-3.4.2 lib/puppet/pops/containment.rb
puppet-3.4.1 lib/puppet/pops/containment.rb
puppet-3.4.0 lib/puppet/pops/containment.rb
puppet-3.4.0.rc2 lib/puppet/pops/containment.rb
puppet-3.4.0.rc1 lib/puppet/pops/containment.rb
puppet-3.3.2 lib/puppet/pops/containment.rb
puppet-3.3.1 lib/puppet/pops/containment.rb
puppet-3.3.1.rc3 lib/puppet/pops/containment.rb
puppet-3.3.1.rc2 lib/puppet/pops/containment.rb
puppet-3.3.1.rc1 lib/puppet/pops/containment.rb
puppet-3.3.0 lib/puppet/pops/containment.rb
puppet-3.3.0.rc3 lib/puppet/pops/containment.rb
puppet-3.3.0.rc2 lib/puppet/pops/containment.rb
puppet-3.2.4 lib/puppet/pops/containment.rb
puppet-3.2.3 lib/puppet/pops/containment.rb
puppet-3.2.3.rc1 lib/puppet/pops/containment.rb
puppet-3.2.2 lib/puppet/pops/containment.rb
puppet-3.2.1 lib/puppet/pops/containment.rb
puppet-3.2.1.rc1 lib/puppet/pops/containment.rb