Class: Puppet::Pops::Binder::Producers::HashMultibindProducer
- Inherits:
-
MultibindProducer
- Object
- Producer
- AbstractArgumentedProducer
- MultibindProducer
- Puppet::Pops::Binder::Producers::HashMultibindProducer
- Defined in:
- lib/puppet/pops/binder/producers.rb
Instance Attribute Summary collapse
-
#conflict_resolution ⇒ Symbol
readonly
One of ‘:error`, `:merge`, `:append`, `:priority`, `:ignore`.
-
#flatten ⇒ Boolean, Integer
readonly
Flatten all if true, or none if false, or to given level (0 = none, -1 = all).
- #uniq ⇒ Boolean readonly
Attributes inherited from MultibindProducer
Attributes inherited from AbstractArgumentedProducer
Attributes inherited from Producer
Instance Method Summary collapse
-
#initialize(injector, binding, scope, options) ⇒ HashMultibindProducer
constructor
The hash multibind producer provides options to control conflict resolution.
Methods inherited from MultibindProducer
Methods inherited from Producer
Constructor Details
#initialize(injector, binding, scope, options) ⇒ HashMultibindProducer
The hash multibind producer provides options to control conflict resolution. By default, the hash is produced using ‘:priority` resolution - the highest entry is selected, the rest are ignored unless they have the same priority which is an error.
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 |
# File 'lib/puppet/pops/binder/producers.rb', line 699 def initialize(injector, binding, scope, ) super @conflict_resolution = [:conflict_resolution].nil? ? :priority : [:conflict_resolution] @uniq = !![:uniq] @flatten = [:flatten] unless [:error, :merge, :append, :priority, :ignore].include?(@conflict_resolution) raise ArgumentError, "Unknown conflict_resolution for Multibind Hash: '#{@conflict_resolution}." end 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 if uniq || flatten || conflict_resolution.to_s == 'append' etype = binding.type.element_type unless etype.class == Puppet::Pops::Types::PDataType || etype.is_a?(Puppet::Pops::Types::PArrayType) detail = [] detail << ":uniq" if uniq detail << ":flatten" if flatten detail << ":conflict_resolution => :append" if conflict_resolution.to_s == 'append' raise ArgumentError, ["Options #{detail.join(', and ')} cannot be used with a Multibind ", "of type #{injector.type_calculator.string(binding.type)}"].join() end end end |
Instance Attribute Details
#conflict_resolution ⇒ Symbol (readonly)
Returns One of ‘:error`, `:merge`, `:append`, `:priority`, `:ignore`.
669 670 671 |
# File 'lib/puppet/pops/binder/producers.rb', line 669 def conflict_resolution @conflict_resolution end |
#flatten ⇒ Boolean, Integer (readonly)
Returns Flatten all if true, or none if false, or to given level (0 = none, -1 = all).
677 678 679 |
# File 'lib/puppet/pops/binder/producers.rb', line 677 def flatten @flatten end |
#uniq ⇒ Boolean (readonly)
673 674 675 |
# File 'lib/puppet/pops/binder/producers.rb', line 673 def uniq @uniq end |