Class: Puppet::Pops::Evaluator::Collectors::FixedSetCollector

Inherits:
AbstractCollector show all
Defined in:
lib/puppet/pops/evaluator/collectors/fixed_set_collector.rb

Constant Summary

Constants inherited from AbstractCollector

AbstractCollector::EMPTY_RESOURCES

Instance Attribute Summary

Attributes inherited from AbstractCollector

#collected, #overrides, #scope

Instance Method Summary collapse

Methods inherited from AbstractCollector

#evaluate

Constructor Details

#initialize(scope, resources) ⇒ FixedSetCollector

Creates a FixedSetCollector using the AbstractCollector constructor to set the scope. It is not possible for a collection to have overrides in this case, since we have a fixed set of resources that can be different types.

Parameters:

  • resources (Array)

    the fixed set of resources we want to realize



10
11
12
13
# File 'lib/puppet/pops/evaluator/collectors/fixed_set_collector.rb', line 10

def initialize(scope, resources)
  super(scope)
  @resources = resources.is_a?(Array) ? resources.dup : [resources]
end

Instance Method Details

#collectObject

Collects a fixed set of resources and realizes them. Used by the realize function



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/puppet/pops/evaluator/collectors/fixed_set_collector.rb', line 17

def collect
  resolved = []
  result = @resources.each_with_object([]) do |ref, memo|
    res = @scope.findresource(ref.to_s)
    next unless res

    res.virtual = false
    memo << res
    resolved << ref
  end

  @resources -= resolved

  @scope.compiler.delete_collection(self) if @resources.empty?

  result
end

#unresolved_resourcesObject



35
36
37
# File 'lib/puppet/pops/evaluator/collectors/fixed_set_collector.rb', line 35

def unresolved_resources
  @resources
end