class Puppet::Pops::Binder::BindingsFactory::BindingsBuilder

Builds a Binding via convenience methods.

@api public

Public Instance Methods

abstract() click to toggle source

Sets the binding to be abstract (it must be overridden) @api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 185
def abstract
  model.abstract = true
  self
end
array_of(t) click to toggle source

Sets the type of the binding to Array, where T is given. @param t [Puppet::Pops::Types::PAnyType] the type of the elements of the array @return [Puppet::Pops::Types::PArrayType] the type @api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 290
def array_of(t)
  type(T.array_of(t))
end
array_of_data() click to toggle source

Sets the type of the binding to Array. @return [Puppet::Pops::Types::PArrayType] the type @api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 282
def array_of_data()
  type(T.array_of_data())
end
boolean() click to toggle source

Sets the type of the binding to Boolean. @return [Puppet::Pops::Types::PBooleanType] the type @api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 247
def boolean()
  type(T.boolean())
end
data() click to toggle source

Sets the type of the binding to the abstract type Data. @return [Puppet::Pops::Types::PDataType] the type @api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 275
def data()
  type(T.data())
end
final() click to toggle source

Sets the binding to be final (it may not be overridden) @api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 199
def final
  model.final = true
  self
end
float() click to toggle source

Sets the type of the binding to Float. @return [Puppet::Pops::Types::PFloatType] the type @api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 240
def float()
  type(T.float())
end
hash_of(t) click to toggle source

Sets type of the binding to `Hash[Literal, t]`. To also limit the key type, use {type} and give it a fully specified hash using {type_factory} and then `#hash_of(value_type, key_type)`. @return [Puppet::Pops::Types::PHashType] the type @api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 306
def hash_of(t)
  type(T.hash_of(t))
end
hash_of_data() click to toggle source

Sets the type of the binding to Hash[Literal, Data]. @return [Puppet::Pops::Types::PHashType] the type @api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 297
def hash_of_data()
  type(T.hash_of_data())
end
in_multibind(id) click to toggle source

Makes the binding a multibind contribution to the given multibind id @param id [String] the multibind id to contribute this binding to @api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 207
def in_multibind(id)
  model.multibind_id = id
  self
end
instance_of(t) click to toggle source

Sets the type of the binding based on the given argument. @overload #instance_of(t)

The same as calling {#type} with `t`.
@param t [Puppet::Pops::Types::PAnyType] the type

@overload #instance_of(o)

Infers the type from the given Ruby object and sets that as the type - i.e. "set the type
of the binding to be that of the given data object".
@param o [Object] the object to infer the type from

@overload #instance_of©

@param c [Class] the Class to base the type on.
Sets the type based on the given ruby class. The result is one of the specific puppet types
if the class can be represented by a specific type, or the open ended PRuntimeType otherwise.

@overload #instance_of(s)

The same as using a class, but instead of giving a class instance, the class is expressed using its fully
qualified name. This method of specifying the type allows late binding (the class does not have to be loaded
before it can be used in a binding).
@param s [String] the fully qualified classname to base the type on.

@return the resulting type @api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 330
def instance_of(t)
  type(T.type_of(t))
end
integer() click to toggle source

Sets the type of the binding to Integer. @return [Puppet::Pops::Types::PIntegerType] the type @api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 233
def integer()
  type(T.integer())
end
name(name) click to toggle source

Sets the name of the binding. @param name [String] the name to bind. @api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 174
def name(name)
  model.name = name
  self
end
Also aliased as: named
named(name) click to toggle source

Same as {name}, but reads better in certain combinations. @api public

Alias for: name
override() click to toggle source

Sets the binding to be override (it must override something) @api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 192
def override
  model.override = true
  self
end
pattern() click to toggle source

Sets the type of the binding to Pattern. @return [Puppet::Pops::Types::PRegexpType] the type @api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 261
def pattern()
  type(T.pattern())
end
producer_options(options) click to toggle source

Sets options to the producer. See the respective producer for the options it supports. All producers supports the option `:transformer`, a puppet or ruby lambda that is evaluated with the produced result as an argument. The ruby lambda gets scope and value as arguments. @note

A Ruby lambda is not cross platform safe. Use a puppet lambda if you want a bindings model that is.

@api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 557
def producer_options(options)
  options.each do |k, v|
    arg = Puppet::Pops::Binder::Bindings::NamedArgument.new()
    arg.name = k.to_s
    arg.value = v
    model.addProducer_args(arg)
  end
  self
end
scalar() click to toggle source

Sets the type of the binding to the abstract type Scalar. @return [Puppet::Pops::Types::PScalarType] the type @api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 268
def scalar()
  type(T.scalar())
end
string() click to toggle source

Sets the type of the binding to String. @return [Puppet::Pops::Types::PStringType] the type @api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 254
def string()
  type(T.string())
end
to(producer, *args) click to toggle source

Sets the binding’s producer to a singleton producer, if given argument is a value, a literal producer is created for it. To create a producer producing an instance of a class with lazy loading of the class, use {to_instance}.

@overload to(a_literal)

Sets a constant producer in the binding.

@overload to(a_class, *args)

Sets an Instantiating producer (producing an instance of the given class)

@overload to(a_producer_descriptor)

Sets the producer from the given producer descriptor

@return [BindingsBuilder] self @api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 355
def to(producer, *args)
  case producer
  when Class
    producer = Puppet::Pops::Binder::BindingsFactory.instance_producer(producer.name, *args)
  when Puppet::Pops::Model::Program
    # program is not an expression
    producer = Puppet::Pops::Binder::BindingsFactory.evaluating_producer(producer.body)
  when Puppet::Pops::Model::Expression
    producer = Puppet::Pops::Binder::BindingsFactory.evaluating_producer(producer)
  when Puppet::Pops::Binder::Bindings::ProducerDescriptor
  else
  # If given producer is not a producer, create a literal producer
    producer = Puppet::Pops::Binder::BindingsFactory.literal_producer(producer)
  end
  model.producer = producer
  self
end
to_first_found(*list_of_lookups) click to toggle source

Sets the binding’s producer to one that produces the first found lookup of another key @param list_of_lookups [Array] array of arrays [type name], or just name (implies data) @example

binder.bind().name('foo').to_first_found('fee', 'fum', 'extended-bar')
binder.bind().name('foo').to_first_found(
  [T.ruby(ThisClass), 'fee'],
  [T.ruby(ThatClass), 'fum'],
  'extended-bar')

@api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 530
def to_first_found(*list_of_lookups)
  producers = list_of_lookups.collect do |entry|
    if entry.is_a?(Array)
      case entry.size
      when 2
        Puppet::Pops::Binder::BindingsFactory.lookup_producer(entry[0], entry[1])
      when 1
        Puppet::Pops::Binder::BindingsFactory.lookup_producer(Puppet::Pops::Types::TypeFactory.data(), entry[0])
      else
        raise ArgumentError, "Not an array of [type, name], name, or [name]"
      end
    else
      Puppet::Pops::Binder::BindingsFactory.lookup_producer(T.data(), entry)
    end
  end
  model.producer = Puppet::Pops::Binder::BindingsFactory.first_found_producer(*producers)
  self
end
to_hash_lookup_of(type, name, key) click to toggle source

Sets the binding’s producer to a one that performs a lookup of another key and they applies hash lookup on the result.

@overload #to_lookup_of(type, name) @overload #to_lookup_of(name) @api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 515
def to_hash_lookup_of(type, name, key)
  model.producer = Puppet::Pops::Binder::BindingsFactory.hash_lookup_producer(type, name, key)
  self
end
to_instance(type, *args) click to toggle source

Sets the binding’s producer to a producer of an instance of given class (a String class name, or a Class instance). Use a string class name when lazy loading of the class is wanted.

@overload #to_instance(class_name, *args)

@param class_name [String] the name of the class to instantiate
@param args [Object] optional arguments to the constructor

@overload #to_instance(a_class)

@param a_class [Class] the class to instantiate
@param args [Object] optional arguments to the constructor
# File lib/puppet/pops/binder/bindings_factory.rb, line 383
def to_instance(type, *args)
  class_name = case type
  when Class
    type.name
  when String
    type
  else
    raise ArgumentError, "to_instance accepts String (a class name), or a Class.*args got: #{type.class}."
  end
  model.producer = Puppet::Pops::Binder::BindingsFactory.instance_producer(class_name, *args)
end
to_lookup_of(type, name=nil) click to toggle source

Sets the binding’s producer to one that performs a lookup of another key @overload #to_lookup_of(type, name) @overload #to_lookup_of(name) @api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 499
def to_lookup_of(type, name=nil)
  unless name
    name = type
    type = Puppet::Pops::Types::TypeFactory.data()
  end
  model.producer = Puppet::Pops::Binder::BindingsFactory.lookup_producer(type, name)
  self
end
to_producer(producer, *args) click to toggle source

Sets the binding’s producer to a singleton producer @overload #to_producer(a_producer)

Sets the producer to an instantiated producer. The resulting model can not be serialized as a consequence as there
is no meta-model describing the specialized producer. Use this only in exceptional cases, or where there is never the
need to serialize the model.
@param a_producer [Puppet::Pops::Binder::Producers::Producer] an instantiated producer, not serializeable !

@overload #to_producer(a_class, *args)

@param a_class [Class] the class to create an instance of
@param args [Object] the arguments to the given class' new

@overload #to_producer(a_producer_descriptor)

@param a_producer_descriptor [Puppet::Pops::Binder::Bindings::ProducerDescriptor] a descriptor
   producing Puppet::Pops::Binder::Producers::Producer

@api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 412
def to_producer(producer, *args)
  case producer
  when Class
    producer = Puppet::Pops::Binder::BindingsFactory.instance_producer(producer.name, *args)
  when Puppet::Pops::Binder::Bindings::ProducerDescriptor
  when Puppet::Pops::Binder::Producers::Producer
    # a custom producer instance
    producer = Puppet::Pops::Binder::BindingsFactory.literal_producer(producer)
  else
    raise ArgumentError, "Given producer argument is none of a producer descriptor, a class, or a producer"
  end
  metaproducer = Puppet::Pops::Binder::BindingsFactory.producer_producer(producer)
  model.producer = metaproducer
  self
end
to_producer_series(producer, *args) click to toggle source

Sets the binding’s producer to a series of producers. Use this when you want to produce a different producer on each request for a producer

@overload #to_producer(a_producer)

Sets the producer to an instantiated producer. The resulting model can not be serialized as a consequence as there
is no meta-model describing the specialized producer. Use this only in exceptional cases, or where there is never the
need to serialize the model.
@param a_producer [Puppet::Pops::Binder::Producers::Producer] an instantiated producer, not serializeable !

@overload #to_producer(a_class, *args)

@param a_class [Class] the class to create an instance of
@param args [Object] the arguments to the given class' new

@overload #to_producer(a_producer_descriptor)

@param a_producer_descriptor [Puppet::Pops::Binder::Bindings::ProducerDescriptor] a descriptor
   producing Puppet::Pops::Binder::Producers::Producer

@api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 447
def to_producer_series(producer, *args)
  case producer
  when Class
    producer = Puppet::Pops::Binder::BindingsFactory.instance_producer(producer.name, *args)
  when Puppet::Pops::Binder::Bindings::ProducerDescriptor
  when Puppet::Pops::Binder::Producers::Producer
    # a custom producer instance
    producer = Puppet::Pops::Binder::BindingsFactory.literal_producer(producer)
  else
    raise ArgumentError, "Given producer argument is none of a producer descriptor, a class, or a producer"
  end
  non_caching = Puppet::Pops::Binder::Bindings::NonCachingProducerDescriptor.new()
  non_caching.producer = producer
  metaproducer = Puppet::Pops::Binder::BindingsFactory.producer_producer(non_caching)

  non_caching = Puppet::Pops::Binder::Bindings::NonCachingProducerDescriptor.new()
  non_caching.producer = metaproducer

  model.producer = non_caching
  self
end
to_series_of(producer, *args) click to toggle source

Sets the binding’s producer to a “non singleton” producer (each call to produce produces a new instance/copy). @overload #to_series_of(a_literal)

a constant producer

@overload #to_series_of(a_class, *args)

Instantiating producer

@overload #to_series_of(a_producer_descriptor)

a given producer

@api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 479
def to_series_of(producer, *args)
  case producer
  when Class
    producer = Puppet::Pops::Binder::BindingsFactory.instance_producer(producer.name, *args)
  when Puppet::Pops::Binder::Bindings::ProducerDescriptor
  else
  # If given producer is not a producer, create a literal producer
    producer = Puppet::Pops::Binder::BindingsFactory.literal_producer(producer)
  end
  non_caching = Puppet::Pops::Binder::Bindings::NonCachingProducerDescriptor.new()
  non_caching.producer = producer
  model.producer = non_caching
  self
end
type(type) click to toggle source

Sets the type of the binding to the given type. @note

This is only needed if something other than the default type `Data` is wanted, or if the wanted type is
not provided by one of the convenience methods {#array_of_data}, {#boolean}, {#float}, {#hash_of_data},
{#integer}, {#scalar}, {#pattern}, {#string}, or one of the collection methods {#array_of}, or {#hash_of}.

To create a type, use the method {type_factory}, to obtain the type. @example creating a Hash with Integer key and Array element type

tc = type_factory
type(tc.hash(tc.array_of(tc.integer), tc.integer)

@param type [Puppet::Pops::Types::PAnyType] the type to set for the binding @api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 225
def type(type)
  model.type = type
  self
end
type_factory() click to toggle source

Provides convenient access to the type factory. This is intended to be used when methods taking a type as argument i.e. {type}, {array_of}, {hash_of}, and {instance_of}. @note

The type factory is also available via the constant {T}.

@api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 339
def type_factory
  Puppet::Pops::Types::TypeFactory
end

Public Class Methods

new(binding) click to toggle source

@param binding [Puppet::Pops::Binder::Bindings::AbstractBinding] the binding to build. @api public

# File lib/puppet/pops/binder/bindings_factory.rb, line 166
def initialize(binding)
  super binding
  data()
end