Sha256: 801fb5b6a25194e5211d1d94dbc4b5fed1085a83c8dd440c84f73340239088be

Contents?: true

Size: 1.65 KB

Versions: 82

Compression:

Stored size: 1.65 KB

Contents

require 'puppet/parser/ast/resource'

class Puppet::Parser::AST
  # Set a parameter on a resource specification created somewhere else in the
  # configuration.  The object is responsible for verifying that this is allowed.
  class ResourceOverride < AST::Branch

    associates_doc

    attr_accessor :object, :parameters

    # Iterate across all of our children.
    def each
      [@object,@parameters].flatten.each { |param|
        #Puppet.debug("yielding param #{param}")
        yield param
      }
    end

    # Does not actually return an object; instead sets an object
    # in the current scope.
    def evaluate(scope)
      # Get our object reference.
      resource = @object.safeevaluate(scope)

      # Evaluate all of the specified params.
      params = @parameters.collect { |param|
        param.safeevaluate(scope)
      }

      # Now we just create a normal resource, but we call a very different
      # method on the scope.
      resource = [resource] unless resource.is_a?(Array)

      resource = resource.collect do |r|

        res = Puppet::Parser::Resource.new(
        r.type, r.title,
          :parameters => params,
          :file => file,
          :line => line,
          :source => scope.source,
          :scope => scope
        )

        # Now we tell the scope that it's an override, and it behaves as
        # necessary.
        scope.compiler.add_override(res)

        res
      end
      # decapsulate array in case of only one item
      return(resource.length == 1 ? resource.pop : resource)
    end

    # Create our ResourceDef.  Handles type checking for us.
    def initialize(hash)
      @checked = false
      super
    end
  end
end

Version data entries

82 entries across 82 versions & 2 rubygems

Version Path
puppet-3.8.3 lib/puppet/parser/ast/resource_override.rb
puppet-3.8.3-x86-mingw32 lib/puppet/parser/ast/resource_override.rb
puppet-3.8.3-x64-mingw32 lib/puppet/parser/ast/resource_override.rb
puppet-retrospec-0.8.0 vendor/gems/puppet-3.7.3/lib/puppet/parser/ast/resource_override.rb
puppet-3.8.2 lib/puppet/parser/ast/resource_override.rb
puppet-3.8.2-x86-mingw32 lib/puppet/parser/ast/resource_override.rb
puppet-3.8.2-x64-mingw32 lib/puppet/parser/ast/resource_override.rb
puppet-retrospec-0.7.3 vendor/gems/puppet-3.7.3/lib/puppet/parser/ast/resource_override.rb
puppet-retrospec-0.7.2 vendor/gems/puppet-3.7.3/lib/puppet/parser/ast/resource_override.rb
puppet-3.8.1 lib/puppet/parser/ast/resource_override.rb
puppet-3.8.1-x86-mingw32 lib/puppet/parser/ast/resource_override.rb
puppet-3.8.1-x64-mingw32 lib/puppet/parser/ast/resource_override.rb
puppet-3.7.5 lib/puppet/parser/ast/resource_override.rb
puppet-3.7.5-x86-mingw32 lib/puppet/parser/ast/resource_override.rb
puppet-3.7.5-x64-mingw32 lib/puppet/parser/ast/resource_override.rb
puppet-3.7.4 lib/puppet/parser/ast/resource_override.rb
puppet-3.7.4-x86-mingw32 lib/puppet/parser/ast/resource_override.rb
puppet-3.7.4-x64-mingw32 lib/puppet/parser/ast/resource_override.rb
puppet-3.7.3 lib/puppet/parser/ast/resource_override.rb
puppet-3.7.3-x86-mingw32 lib/puppet/parser/ast/resource_override.rb