Sha256: 1c67b98f6b6530841b4c5ed6fe97523461ee9d515642b3a4f4ee6906c14ec2d0

Contents?: true

Size: 1.56 KB

Versions: 24

Compression:

Stored size: 1.56 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)
    if Puppet[:tasks]
      raise Puppet::ParseErrorWithIssue.from_issue_and_stack(
        Puppet::Pops::Issues::CATALOG_OPERATION_NOT_SUPPORTED_WHEN_SCRIPTING,
        {:operation => 'contain'})
    end

    # 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

24 entries across 24 versions & 2 rubygems

Version Path
bolt-0.17.1 vendored/puppet/lib/puppet/functions/contain.rb
bolt-0.17.0 vendored/puppet/lib/puppet/functions/contain.rb
bolt-0.16.4 vendored/puppet/lib/puppet/functions/contain.rb
bolt-0.16.3 vendored/puppet/lib/puppet/functions/contain.rb
bolt-0.16.2 vendored/puppet/lib/puppet/functions/contain.rb
puppet-5.4.0 lib/puppet/functions/contain.rb
puppet-5.4.0-x86-mingw32 lib/puppet/functions/contain.rb
puppet-5.4.0-x64-mingw32 lib/puppet/functions/contain.rb
puppet-5.4.0-universal-darwin lib/puppet/functions/contain.rb
bolt-0.16.1 vendored/puppet/lib/puppet/functions/contain.rb
bolt-0.16.0 vendored/puppet/lib/puppet/functions/contain.rb
bolt-0.15.0 vendored/puppet/lib/puppet/functions/contain.rb
bolt-0.14.0 vendored/puppet/lib/puppet/functions/contain.rb
bolt-0.13.0 vendored/puppet/lib/puppet/functions/contain.rb
bolt-0.12.0 vendored/puppet/lib/puppet/functions/contain.rb
bolt-0.11.0 vendored/puppet/lib/puppet/functions/contain.rb
bolt-0.10.0 vendored/puppet/lib/puppet/functions/contain.rb
bolt-0.9.0 vendored/puppet/lib/puppet/functions/contain.rb
bolt-0.8.0 vendored/puppet/lib/puppet/functions/contain.rb
bolt-0.7.0 vendored/puppet/lib/puppet/functions/contain.rb