Class: Puppet::Pops::Binder::Producers::ProducerProducer

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

Overview

A ProducerProducer creates a producer via another producer, and then uses this created producer to produce values. This is useful for custom production of series of values. On each request for a producer, this producer will reset its internal producer (i.e. restarting the series).

Instance Attribute Summary collapse

Attributes inherited from Producer

#transformer

Instance Method Summary collapse

Methods inherited from Producer

#produce

Constructor Details

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

Creates new ProducerProducer given a producer.

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

  • :producer_producer (Producer)

    a producer of a value producer (required)

Raises:

  • (ArgumentError)


434
435
436
437
438
439
440
441
442
443
# File 'lib/puppet/pops/binder/producers.rb', line 434

def initialize(injector, binding, scope, options)
  super
  unless producer_producer = options[:producer_producer]
    raise ArgumentError, "The option :producer_producer must be set in a ProducerProducer"
  end
  raise ArgumentError, "Argument must be a Producer" unless producer_producer.is_a?(Producer)

  @producer_producer = producer_producer
  @value_producer = nil
end

Instance Attribute Details

#producer_producerObject (readonly)



419
420
421
# File 'lib/puppet/pops/binder/producers.rb', line 419

def producer_producer
  @producer_producer
end

#value_producerObject (readonly)



422
423
424
# File 'lib/puppet/pops/binder/producers.rb', line 422

def value_producer
  @value_producer
end

Instance Method Details

#producer(scope) ⇒ Object

Updates the internal state to use a new instance of the wrapped producer.



448
449
450
451
# File 'lib/puppet/pops/binder/producers.rb', line 448

def producer(scope)
  @value_producer = @producer_producer.produce(scope)
  self
end