Class: Puppet::Pops::Binder::Producers::ArrayMultibindProducer
- Inherits:
-
MultibindProducer
- Object
- Producer
- AbstractArgumentedProducer
- MultibindProducer
- Puppet::Pops::Binder::Producers::ArrayMultibindProducer
- Defined in:
- lib/puppet/pops/binder/producers.rb
Overview
Collection accepts elements that comply with the array’s element type, or the entire type (i.e. Array). If the type is restrictive - e.g. Array and an Array is contributed, the result will not be type compliant without also using the ‘:flatten` option, and a type error will be raised. For an array with relaxed typing i.e. Array, it is valid to produce a result such as `[’a’, [‘b’, ‘c’], ‘d’]‘ and no flattening is required and no error is raised (but using the array needs to be aware of potential array, non-array entries. The use of the option `:flatten` controls how the result is flattened.
A configurable multibind producer for Array type multibindings.
This implementation collects all contributions to the multibind and then combines them using the following rules:
-
all unnamed entries are added unless the option ‘:priority_on_unnamed` is set to true, in which case the unnamed contribution with the highest priority is added, and the rest are ignored (unless they have the same priority in which case an error is raised).
-
all named entries are handled the same way as unnamed but the option ‘:priority_on_named` controls their handling.
-
the option ‘:uniq` post processes the result to only contain unique entries
-
the option ‘:flatten` post processes the result by flattening all nested arrays.
-
If both ‘:flatten` and `:uniq` are true, flattening is done first.
Instance Attribute Summary collapse
-
#flatten ⇒ Boolean, Integer
readonly
If result should be flattened (true), or not (false), or flattened to given level (0 = none, -1 = all).
-
#priority_on_named ⇒ Boolean
readonly
Whether priority should be considered for named contributions.
-
#priority_on_unnamed ⇒ Boolean
readonly
Whether priority should be considered for unnamed contributions.
-
#uniq ⇒ Boolean
readonly
Whether the result should be made contain unique (non-equal) entries or not.
Attributes inherited from MultibindProducer
Attributes inherited from AbstractArgumentedProducer
Attributes inherited from Producer
Instance Method Summary collapse
-
#initialize(injector, binding, scope, options) ⇒ ArrayMultibindProducer
constructor
A new instance of ArrayMultibindProducer.
Methods inherited from MultibindProducer
Methods inherited from Producer
Constructor Details
#initialize(injector, binding, scope, options) ⇒ ArrayMultibindProducer
Returns a new instance of ArrayMultibindProducer.
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 |
# File 'lib/puppet/pops/binder/producers.rb', line 592 def initialize(injector, binding, scope, ) super @uniq = !![:uniq] @flatten = [:flatten] @priority_on_named = [:priority_on_named].nil? ? true : [:priority_on_name] @priority_on_unnamed = !![:priority_on_unnamed] case @flatten when Integer when true @flatten = -1 when false @flatten = nil when NilClass @flatten = nil else raise ArgumentError, "Option :flatten must be nil, Boolean, or an integer value" unless @flatten.is_a?(Integer) end end |
Instance Attribute Details
#flatten ⇒ Boolean, Integer (readonly)
Returns If result should be flattened (true), or not (false), or flattened to given level (0 = none, -1 = all).
571 572 573 |
# File 'lib/puppet/pops/binder/producers.rb', line 571 def flatten @flatten end |
#priority_on_named ⇒ Boolean (readonly)
Returns whether priority should be considered for named contributions.
575 576 577 |
# File 'lib/puppet/pops/binder/producers.rb', line 575 def priority_on_named @priority_on_named end |
#priority_on_unnamed ⇒ Boolean (readonly)
Returns whether priority should be considered for unnamed contributions.
579 580 581 |
# File 'lib/puppet/pops/binder/producers.rb', line 579 def priority_on_unnamed @priority_on_unnamed end |
#uniq ⇒ Boolean (readonly)
Returns whether the result should be made contain unique (non-equal) entries or not.
567 568 569 |
# File 'lib/puppet/pops/binder/producers.rb', line 567 def uniq @uniq end |