Class: Puppet::Pops::Evaluator::Collectors::AbstractCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/pops/evaluator/collectors/abstract_collector.rb

Constant Summary collapse

EMPTY_RESOURCES =

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

[].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope, overrides = nil) ⇒ AbstractCollector

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

Parameters:



25
26
27
28
29
30
31
32
33
34
# 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

Instance Attribute Details

#collectedObject (readonly)

The set of collected resources



8
9
10
# File 'lib/puppet/pops/evaluator/collectors/abstract_collector.rb', line 8

def collected
  @collected
end

#overridesObject (readonly)

The collector’s hash of overrides => params



5
6
7
# File 'lib/puppet/pops/evaluator/collectors/abstract_collector.rb', line 5

def overrides
  @overrides
end

#scopeObject (readonly)



2
3
4
# File 'lib/puppet/pops/evaluator/collectors/abstract_collector.rb', line 2

def scope
  @scope
end

Instance Method Details

#collectArray

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

Returns:

  • (Array)

    the collected resources

Raises:

  • (NotImplementedError)


83
84
85
# 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

#evaluateArray

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

Returns:

  • (Array)

    the resources we have collected



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# 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.reduce(@collected) { |c,o| c[o.ref]=o; c }

  objects
end

#unresolved_resourcesArray

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

Returns:

  • (Array)

    the resources that have not been resolved



74
75
76
# File 'lib/puppet/pops/evaluator/collectors/abstract_collector.rb', line 74

def unresolved_resources
  EMPTY_RESOURCES
end