Class: Puppet::Pops::Binder::Producers::InstantiatingProducer

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

Instance Attribute Summary collapse

Attributes inherited from AbstractArgumentedProducer

#binding, #injector

Attributes inherited from Producer

#transformer

Instance Method Summary collapse

Methods inherited from Producer

#produce, #producer

Constructor Details

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

Returns a new instance of InstantiatingProducer.

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):

  • :transformer (Model::LambdaExpression) — default: nil

    a transformer of produced value

  • :class_name (String)

    The name of the class to create instance of

  • :init_args (Array<Object>) — default: []

    Optional arguments to class constructor

Raises:

  • (ArgumentError)


218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/puppet/pops/binder/producers.rb', line 218

def initialize(injector, binding, scope, options)
  # Better do this, even if a transformation of a created instance is kind of an odd thing to do, one can imagine
  # sending it to a function for further detailing.
  #
  super
  class_name = options[:class_name]
  raise ArgumentError, "Option 'class_name' must be given for an InstantiatingProducer" unless class_name
  # get class by name
  @the_class = Types::ClassLoader.provide(class_name)
  @init_args = options[:init_args] || []
  raise ArgumentError, "Can not load the class #{class_name} specified in binding named: '#{binding.name}'" unless @the_class
end

Instance Attribute Details

#init_argsObject (readonly)



208
209
210
# File 'lib/puppet/pops/binder/producers.rb', line 208

def init_args
  @init_args
end

#the_classObject (readonly)



205
206
207
# File 'lib/puppet/pops/binder/producers.rb', line 205

def the_class
  @the_class
end