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:

Options Hash (options):

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

    a transformer of produced value

  • :producer_producer (Puppet::Pops::Binder::Producer)

    a producer of a value producer (required)

Raises:

  • (ArgumentError)


431
432
433
434
435
436
437
438
439
440
# File 'lib/puppet/pops/binder/producers.rb', line 431

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)



416
417
418
# File 'lib/puppet/pops/binder/producers.rb', line 416

def producer_producer
  @producer_producer
end

#value_producerObject (readonly)



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

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.



445
446
447
448
# File 'lib/puppet/pops/binder/producers.rb', line 445

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