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



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

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



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

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



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

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