class Puppet::Pops::Evaluator::Collectors::AbstractCollector

Constants

EMPTY_RESOURCES

An empty array which will be returned by the #unresolved_resources method unless we have a FixSetCollector

Attributes

collected[R]

The set of collected resources

overrides[R]

The collector’s hash of overrides {:parameters => params}

scope[R]

Public Instance Methods

collect() click to toggle source

Collect the specified resources. The way this is done depends on which type of collector we are dealing with. This method is implemented differently in each of the three child classes

@return [Array] the collected resources

# File lib/puppet/pops/evaluator/collectors/abstract_collector.rb, line 83
def collect
  raise NotImplementedError, "This method must be implemented by the child class"
end
evaluate() click to toggle source

Collects resources and marks collected objects as non-virtual. Also handles overrides.

@return [Array] the resources we have collected

# File lib/puppet/pops/evaluator/collectors/abstract_collector.rb, line 40
def evaluate
  objects = collect.each do |obj|
    obj.virtual = false
  end

  return false if objects.empty?

  if @overrides and !objects.empty?
    overrides[:source].meta_def(:child_of?) do |klass|
      true
    end

    objects.each do |res|
      unless @collected.include?(res.ref)
        newres = Puppet::Parser::Resource.new(res.type, res.title, @overrides)
        scope.compiler.add_override(newres)
      end
    end
  end

  objects.reject! { |o| @collected.include?(o.ref) }

  return false if objects.empty?

  objects.inject(@collected) { |c,o| c[o.ref]=o; c }

  objects
end
unresolved_resources() click to toggle source

This should only return an empty array unless we have an FixedSetCollector, in which case it will return the resources that have not yet been realized

@return [Array] the resources that have not been resolved

# File lib/puppet/pops/evaluator/collectors/abstract_collector.rb, line 74
def unresolved_resources
  EMPTY_RESOURCES
end

Public Class Methods

new(scope, overrides = nil) click to toggle source

Initialized the instance variables needed by the base collector class to perform evaluation

@param [Puppet::Parser::Scope] scope

@param [Hash] overrides a hash of optional overrides @options opts [Array] :parameters @options opts [String] :file @options opts [Array] :line @options opts [Puppet::Resource::Type] :source @options opts [Puppet::Parser::Scope] :scope

# File lib/puppet/pops/evaluator/collectors/abstract_collector.rb, line 25
def initialize(scope, overrides = nil)
  @collected = {}
  @scope = scope

  if !(overrides.nil? || overrides[:parameters])
    raise ArgumentError, "Exported resource try to override without parameters"
  end

  @overrides = overrides
end