Class: Puppet::Pops::Binder::BindingsFactory::BindingsBuilder
- Inherits:
-
AbstractBuilder
- Object
- AbstractBuilder
- Puppet::Pops::Binder::BindingsFactory::BindingsBuilder
- Defined in:
- lib/puppet/pops/binder/bindings_factory.rb
Overview
Builds a Binding via convenience methods.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from AbstractBuilder
Instance Method Summary collapse
-
#abstract ⇒ Object
Sets the binding to be abstract (it must be overridden).
-
#array_of(t) ⇒ Puppet::Pops::Types::PArrayType
Sets the type of the binding to Array, where T is given.
-
#array_of_data ⇒ Puppet::Pops::Types::PArrayType
Sets the type of the binding to Array.
-
#boolean ⇒ Puppet::Pops::Types::PBooleanType
Sets the type of the binding to Boolean.
-
#data ⇒ Puppet::Pops::Types::PDataType
Sets the type of the binding to the abstract type Data.
-
#final ⇒ Object
Sets the binding to be final (it may not be overridden).
-
#float ⇒ Puppet::Pops::Types::PFloatType
Sets the type of the binding to Float.
-
#hash_of(t) ⇒ Puppet::Pops::Types::PHashType
Sets type of the binding to ‘Hash[Literal, t]`.
-
#hash_of_data ⇒ Puppet::Pops::Types::PHashType
Sets the type of the binding to Hash[Literal, Data].
-
#in_multibind(id) ⇒ Object
Makes the binding a multibind contribution to the given multibind id.
-
#initialize(binding) ⇒ BindingsBuilder
constructor
A new instance of BindingsBuilder.
-
#instance_of(t) ⇒ Object
Sets the type of the binding based on the given argument.
-
#integer ⇒ Puppet::Pops::Types::PIntegerType
Sets the type of the binding to Integer.
-
#name(name) ⇒ Object
(also: #named)
Sets the name of the binding.
-
#override ⇒ Object
Sets the binding to be override (it must override something).
-
#pattern ⇒ Puppet::Pops::Types::PRegexpType
Sets the type of the binding to Pattern.
-
#producer_options(options) ⇒ Object
Sets options to the producer.
-
#scalar ⇒ Puppet::Pops::Types::PScalarType
Sets the type of the binding to the abstract type Scalar.
-
#string ⇒ Puppet::Pops::Types::PStringType
Sets the type of the binding to String.
-
#to(producer, *args) ⇒ BindingsBuilder
Sets the binding’s producer to a singleton producer, if given argument is a value, a literal producer is created for it.
-
#to_first_found(*list_of_lookups) ⇒ Object
Sets the binding’s producer to one that produces the first found lookup of another key.
-
#to_hash_lookup_of(type, name, key) ⇒ Object
Sets the binding’s producer to a one that performs a lookup of another key and they applies hash lookup on the result.
-
#to_instance(type, *args) ⇒ Object
Sets the binding’s producer to a producer of an instance of given class (a String class name, or a Class instance).
-
#to_lookup_of(type, name = nil) ⇒ Object
Sets the binding’s producer to one that performs a lookup of another key.
-
#to_producer(producer, *args) ⇒ Object
Sets the binding’s producer to a singleton producer.
-
#to_producer_series(producer, *args) ⇒ Object
Sets the binding’s producer to a series of producers.
-
#to_series_of(producer, *args) ⇒ Object
Sets the binding’s producer to a “non singleton” producer (each call to produce produces a new instance/copy).
-
#type(type) ⇒ Object
Sets the type of the binding to the given type.
-
#type_factory ⇒ Object
Provides convenient access to the type factory.
Methods inherited from AbstractBuilder
Constructor Details
#initialize(binding) ⇒ BindingsBuilder
Returns a new instance of BindingsBuilder.
166 167 168 169 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 166 def initialize(binding) super binding data() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Puppet::Pops::Binder::BindingsFactory::AbstractBuilder
Instance Method Details
#abstract ⇒ Object
Sets the binding to be abstract (it must be overridden)
185 186 187 188 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 185 def abstract model.abstract = true self end |
#array_of(t) ⇒ Puppet::Pops::Types::PArrayType
Sets the type of the binding to Array, where T is given.
290 291 292 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 290 def array_of(t) type(T.array_of(t)) end |
#array_of_data ⇒ Puppet::Pops::Types::PArrayType
Sets the type of the binding to Array.
282 283 284 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 282 def array_of_data() type(T.array_of_data()) end |
#boolean ⇒ Puppet::Pops::Types::PBooleanType
Sets the type of the binding to Boolean.
247 248 249 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 247 def boolean() type(T.boolean()) end |
#data ⇒ Puppet::Pops::Types::PDataType
Sets the type of the binding to the abstract type Data.
275 276 277 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 275 def data() type(T.data()) end |
#final ⇒ Object
Sets the binding to be final (it may not be overridden)
199 200 201 202 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 199 def final model.final = true self end |
#float ⇒ Puppet::Pops::Types::PFloatType
Sets the type of the binding to Float.
240 241 242 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 240 def float() type(T.float()) end |
#hash_of(t) ⇒ Puppet::Pops::Types::PHashType
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)`.
306 307 308 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 306 def hash_of(t) type(T.hash_of(t)) end |
#hash_of_data ⇒ Puppet::Pops::Types::PHashType
Sets the type of the binding to Hash[Literal, Data].
297 298 299 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 297 def hash_of_data() type(T.hash_of_data()) end |
#in_multibind(id) ⇒ Object
Makes the binding a multibind contribution to the given multibind id
207 208 209 210 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 207 def in_multibind(id) model.multibind_id = id self end |
#instance_of(t) ⇒ Object #instance_of(o) ⇒ Object #instance_of(c) ⇒ Object #instance_of(s) ⇒ Object
Sets the type of the binding based on the given argument.
330 331 332 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 330 def instance_of(t) type(T.type_of(t)) end |
#integer ⇒ Puppet::Pops::Types::PIntegerType
Sets the type of the binding to Integer.
233 234 235 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 233 def integer() type(T.integer()) end |
#name(name) ⇒ Object Also known as: named
Sets the name of the binding.
174 175 176 177 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 174 def name(name) model.name = name self end |
#override ⇒ Object
Sets the binding to be override (it must override something)
192 193 194 195 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 192 def override model.override = true self end |
#pattern ⇒ Puppet::Pops::Types::PRegexpType
Sets the type of the binding to Pattern.
261 262 263 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 261 def pattern() type(T.pattern()) end |
#producer_options(options) ⇒ Object
A Ruby lambda is not cross platform safe. Use a puppet lambda if you want a bindings model that is.
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.
561 562 563 564 565 566 567 568 569 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 561 def () .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 ⇒ Puppet::Pops::Types::PScalarType
Sets the type of the binding to the abstract type Scalar.
268 269 270 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 268 def scalar() type(T.scalar()) end |
#string ⇒ Puppet::Pops::Types::PStringType
Sets the type of the binding to String.
254 255 256 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 254 def string() type(T.string()) end |
#to(a_literal) ⇒ BindingsBuilder #to(a_class, *args) ⇒ BindingsBuilder #to(a_producer_descriptor) ⇒ BindingsBuilder
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.
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
# 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) ⇒ Object
Sets the binding’s producer to one that produces the first found lookup of another key
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 534 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_lookup_of(type, name) ⇒ Object #to_lookup_of(name) ⇒ Object
Sets the binding’s producer to a one that performs a lookup of another key and they applies hash lookup on the result.
519 520 521 522 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 519 def to_hash_lookup_of(type, name, key) model.producer = Puppet::Pops::Binder::BindingsFactory.hash_lookup_producer(type, name, key) self end |
#to_instance(class_name, *args) ⇒ Object #to_instance(a_class) ⇒ Object
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.
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
# 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 # Help by setting the type - since if an to_instance is bound, the type is know. This avoids having # to specify the same thing twice. self.instance_of(type) model.producer = Puppet::Pops::Binder::BindingsFactory.instance_producer(class_name, *args) end |
#to_lookup_of(type, name) ⇒ Object #to_lookup_of(name) ⇒ Object
Sets the binding’s producer to one that performs a lookup of another key
503 504 505 506 507 508 509 510 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 503 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(a_producer) ⇒ Object #to_producer(a_class, *args) ⇒ Object #to_producer(a_producer_descriptor) ⇒ Object
Sets the binding’s producer to a singleton producer
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 416 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 = Puppet::Pops::Binder::BindingsFactory.producer_producer(producer) model.producer = self end |
#to_producer(a_producer) ⇒ Object #to_producer(a_class, *args) ⇒ Object #to_producer(a_producer_descriptor) ⇒ Object
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
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 451 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 = Puppet::Pops::Binder::BindingsFactory.producer_producer(non_caching) non_caching = Puppet::Pops::Binder::Bindings::NonCachingProducerDescriptor.new() non_caching.producer = model.producer = non_caching self end |
#to_series_of(a_literal) ⇒ Object #to_series_of(a_class, *args) ⇒ Object #to_series_of(a_producer_descriptor) ⇒ Object
Sets the binding’s producer to a “non singleton” producer (each call to produce produces a new instance/copy).
483 484 485 486 487 488 489 490 491 492 493 494 495 496 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 483 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) ⇒ Object
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.
Sets the type of the binding to the given type. To create a type, use the method #type_factory, to obtain the type.
225 226 227 228 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 225 def type(type) model.type = type self end |
#type_factory ⇒ Object
The type factory is also available via the constant T.
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.
339 340 341 |
# File 'lib/puppet/pops/binder/bindings_factory.rb', line 339 def type_factory Puppet::Pops::Types::TypeFactory end |