class Puppet::Pops::Binder::Producers::ProducerProducer

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

@param #producer_producer [produce(scope)] the producer of the producer

@api public

Attributes

producer_producer[R]

@api public

value_producer[R]

@api public

Public Instance Methods

producer(scope) click to toggle source

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

# File lib/puppet/pops/binder/producers.rb, line 445
def producer(scope)
  @value_producer = @producer_producer.produce(scope)
  self
end

Protected Instance Methods

internal_produce(scope, *args) click to toggle source

Produces a value after having created an instance of the wrapped producer (if not already created). @api private

# File lib/puppet/pops/binder/producers.rb, line 455
def internal_produce(scope, *args)
  producer() unless value_producer
  value_producer.produce(scope)
end

Public Class Methods

new(injector, binding, scope, options) click to toggle source

Creates new ProducerProducer given a producer.

@param injector [Puppet::Pops::Binder::Injector] The injector where the lookup originates @param binding [Puppet::Pops::Binder::Bindings::Binding, nil] The binding using this producer @param scope [Puppet::Parser::Scope] The scope to use for evaluation @option options [Puppet::Pops::Model::LambdaExpression] :transformer (nil) a transformer of produced value @option options [Puppet::Pops::Binder::Producer] :#producer_producer a producer of a value producer (required)

@api public

# 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