Class: Puppet::Pops::Binder::Producers::EvaluatingProducer

Inherits:
Producer show all
Defined in:
lib/puppet/pops/binder/producers.rb

Overview

Evaluates a Puppet Expression and returns the result. This is typically used for strings with interpolated expressions.

Instance Attribute Summary collapse

Attributes inherited from Producer

#transformer

Instance Method Summary collapse

Methods inherited from Producer

#produce, #producer

Constructor Details

#initialize(injector, binding, scope, options) ⇒ EvaluatingProducer

Returns a new instance of EvaluatingProducer.

Parameters:

  • injector (Injector)

    The injector where the lookup originates

  • binding (Bindings::Binding, nil)

    The binding using this producer

  • scope (Puppet::Parser::Scope)

    The scope to use for evaluation

  • options (Hash)

    a customizable set of options

Options Hash (options):

Raises:

  • (ArgumentError)


301
302
303
304
305
# File 'lib/puppet/pops/binder/producers.rb', line 301

def initialize(injector, binding, scope, options)
  super
  @expression = options[:expression]
  raise ArgumentError, "Option 'expression' must be given to an EvaluatingProducer." unless @expression
end

Instance Attribute Details

#expressionObject (readonly)

A Puppet 3 AST Expression



292
293
294
# File 'lib/puppet/pops/binder/producers.rb', line 292

def expression
  @expression
end

Instance Method Details

#internal_produce(scope) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



308
309
310
# File 'lib/puppet/pops/binder/producers.rb', line 308

def internal_produce(scope)
  Parser::EvaluatingParser.new.evaluate(scope, expression)
end