Class: Puppet::Pops::Evaluator::Collectors::AbstractCollector
- Defined in:
- lib/puppet/pops/evaluator/collectors/abstract_collector.rb
Direct Known Subclasses
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
-
#collected ⇒ Object
readonly
The set of collected resources.
-
#overrides ⇒ Object
readonly
The collector’s hash of overrides => params.
- #scope ⇒ Object readonly
Instance Method Summary collapse
-
#collect ⇒ Array
Collect the specified resources.
-
#evaluate ⇒ Array
Collects resources and marks collected objects as non-virtual.
-
#initialize(scope, overrides = nil) ⇒ AbstractCollector
constructor
Initialized the instance variables needed by the base collector class to perform evaluation.
-
#unresolved_resources ⇒ Array
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.
Constructor Details
#initialize(scope, overrides = nil) ⇒ AbstractCollector
Initialized the instance variables needed by the base collector class to perform evaluation
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/puppet/pops/evaluator/collectors/abstract_collector.rb', line 27 def initialize(scope, overrides = nil) @collected = {} @scope = scope unless overrides.nil? || overrides[:parameters] raise ArgumentError, _("Exported resource try to override without parameters") end @overrides = overrides end |
Instance Attribute Details
#collected ⇒ Object (readonly)
The set of collected resources
10 11 12 |
# File 'lib/puppet/pops/evaluator/collectors/abstract_collector.rb', line 10 def collected @collected end |
#overrides ⇒ Object (readonly)
The collector’s hash of overrides => params
7 8 9 |
# File 'lib/puppet/pops/evaluator/collectors/abstract_collector.rb', line 7 def overrides @overrides end |
#scope ⇒ Object (readonly)
4 5 6 |
# File 'lib/puppet/pops/evaluator/collectors/abstract_collector.rb', line 4 def scope @scope end |
Instance Method Details
#collect ⇒ Array
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
85 86 87 |
# File 'lib/puppet/pops/evaluator/collectors/abstract_collector.rb', line 85 def collect raise NotImplementedError, "This method must be implemented by the child class" end |
#evaluate ⇒ Array
Collects resources and marks collected objects as non-virtual. Also handles overrides.
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 68 69 |
# File 'lib/puppet/pops/evaluator/collectors/abstract_collector.rb', line 42 def evaluate objects = collect.each do |obj| obj.virtual = false end return false if objects.empty? if @overrides and !objects.empty? overrides[:source].override = true objects.each do |res| next if @collected.include?(res.ref) t = res.type t = Puppet::Pops::Evaluator::Runtime3ResourceSupport.find_resource_type(scope, t) newres = Puppet::Parser::Resource.new(t, res.title, @overrides) scope.compiler.add_override(newres) end end objects.reject! { |o| @collected.include?(o.ref) } return false if objects.empty? objects.each_with_object(@collected) { |o, c| c[o.ref] = o; } objects end |
#unresolved_resources ⇒ Array
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
76 77 78 |
# File 'lib/puppet/pops/evaluator/collectors/abstract_collector.rb', line 76 def unresolved_resources EMPTY_RESOURCES end |