Sha256: 07f909997bc98c6941a4bf5ef3a01410575e4f2583f73830794d1a98cdb728a3

Contents?: true

Size: 1.36 KB

Versions: 124

Compression:

Stored size: 1.36 KB

Contents

# Called within a class definition, establishes a containment
# relationship with another class
# For documentation, see the 3.x stub
#
Puppet::Functions.create_function(:contain, Puppet::Functions::InternalFunction) do
  dispatch :contain do
    scope_param
    # The function supports what the type system sees as Ruby runtime objects, and
    # they cannot be parameterized to find what is actually valid instances.
    # The validation is instead done in the function body itself via a call to
    # `transform_and_assert_classnames` on the calling scope.
    required_repeated_param 'Any', :names
  end

  def contain(scope, *classes)
    # Make call patterns uniform and protected against nested arrays, also make
    # names absolute if so desired.
    classes = scope.transform_and_assert_classnames(classes.flatten)

    result = classes.map {|name| Puppet::Pops::Types::TypeFactory.host_class(name) }
    containing_resource = scope.resource

    # This is the same as calling the include function but faster and does not rely on the include
    # function.
    (scope.compiler.evaluate_classes(classes, scope, false) || []).each do |resource|
      if ! scope.catalog.edge?(containing_resource, resource)
        scope.catalog.add_edge(containing_resource, resource)
      end
    end
    # Result is an Array[Class, 1, n] which allows chaining other operations
    result
  end
end

Version data entries

124 entries across 124 versions & 2 rubygems

Version Path
puppet-retrospec-1.8.0 vendor/pup410/lib/puppet/functions/contain.rb
puppet-retrospec-1.7.0 vendor/pup410/lib/puppet/functions/contain.rb
puppet-5.3.7 lib/puppet/functions/contain.rb
puppet-5.3.7-x86-mingw32 lib/puppet/functions/contain.rb
puppet-5.3.7-x64-mingw32 lib/puppet/functions/contain.rb
puppet-5.3.7-universal-darwin lib/puppet/functions/contain.rb
puppet-4.10.12 lib/puppet/functions/contain.rb
puppet-4.10.12-x86-mingw32 lib/puppet/functions/contain.rb
puppet-4.10.12-x64-mingw32 lib/puppet/functions/contain.rb
puppet-4.10.12-universal-darwin lib/puppet/functions/contain.rb
puppet-4.10.11 lib/puppet/functions/contain.rb
puppet-4.10.11-x86-mingw32 lib/puppet/functions/contain.rb
puppet-4.10.11-x64-mingw32 lib/puppet/functions/contain.rb
puppet-4.10.11-universal-darwin lib/puppet/functions/contain.rb
puppet-5.3.6 lib/puppet/functions/contain.rb
puppet-5.3.6-x86-mingw32 lib/puppet/functions/contain.rb
puppet-5.3.6-x64-mingw32 lib/puppet/functions/contain.rb
puppet-5.3.6-universal-darwin lib/puppet/functions/contain.rb
puppet-5.3.5 lib/puppet/functions/contain.rb
puppet-5.3.5-x86-mingw32 lib/puppet/functions/contain.rb