Class: Puppet::Pops::Evaluator::Collectors::CatalogCollector

Inherits:
AbstractCollector show all
Defined in:
lib/puppet/pops/evaluator/collectors/catalog_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, #unresolved_resources

Constructor Details

#initialize(scope, type, query, overrides = nil) ⇒ CatalogCollector

Creates a CatalogCollector using the AbstractCollector’s constructor to set the scope and overrides

param [Puppet::CompilableResourceType] type the resource type to be collected param [Proc] query the query which defines which resources to match



8
9
10
11
12
13
14
# File 'lib/puppet/pops/evaluator/collectors/catalog_collector.rb', line 8

def initialize(scope, type, query, overrides = nil)
  super(scope, overrides)

  @query = query

  @type = Puppet::Resource.new(type, 'whatever').type
end

Instance Method Details

#collectObject

Collects virtual resources based off a collection in a manifest



17
18
19
20
21
22
23
24
# File 'lib/puppet/pops/evaluator/collectors/catalog_collector.rb', line 17

def collect
  t = @type
  q = @query

  scope.compiler.resources.find_all do |resource|
    resource.type == t && (q ?  q.call(resource) : true)
  end
end

#to_sObject



26
27
28
# File 'lib/puppet/pops/evaluator/collectors/catalog_collector.rb', line 26

def to_s
  "Catalog-Collector[#{@type.to_s}]"
end