Class: Puppet::Pops::Evaluator::CollectorTransformer

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

Instance Method Summary collapse

Constructor Details

#initializeCollectorTransformer

Returns a new instance of CollectorTransformer.



6
7
8
9
10
11
# File 'lib/puppet/pops/evaluator/collector_transformer.rb', line 6

def initialize
  @@query_visitor    ||= Visitor.new(nil, "query", 1, 1)
  @@match_visitor    ||= Visitor.new(nil, "match", 1, 1)
  @@evaluator        ||= EvaluatorImpl.new
  @@compare_operator ||= CompareOperator.new()
end

Instance Method Details

#transform(o, scope) ⇒ Object

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/puppet/pops/evaluator/collector_transformer.rb', line 13

def transform(o, scope)
  # TRANSLATORS 'CollectExpression' is a class name and should not be translated
  raise ArgumentError, _("Expected CollectExpression") unless o.is_a? Model::CollectExpression

  raise "LHS is not a type" unless o.type_expr.is_a? Model::QualifiedReference

  type = o.type_expr.value().downcase()

  if type == 'class'
    fail "Classes cannot be collected"
  end

  resource_type = Runtime3ResourceSupport.find_resource_type(scope, type)

  fail "Resource type #{type} doesn't exist" unless resource_type

  unless o.operations.empty?
    overrides = {
      :parameters => o.operations.map { |x| @@evaluator.evaluate(x, scope) }.flatten,
      :file => o.file,
      :line => o.line,
      :source => scope.source,
      :scope => scope
    }
  end

  code = query_unless_nop(o.query, scope)

  case o.query
  when Model::VirtualQuery
    newcoll = Collectors::CatalogCollector.new(scope, resource_type, code, overrides)
  when Model::ExportedQuery
    match = match_unless_nop(o.query, scope)
    newcoll = Collectors::ExportedCollector.new(scope, resource_type, match, code, overrides)
  end

  scope.compiler.add_collection(newcoll)

  newcoll
end