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.


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

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


16
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 16

def collect
  resolved = []
  result = @resources.reduce([]) do |memo, ref|
    res = @scope.findresource(ref.to_s)
    if res
      res.virtual = false
      memo << res
      resolved << ref
    end
    memo
  end

  @resources = @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