Class: Puppet::Pops::Types::Iterable::TreeIterator Private
- Includes:
- Puppet::Pops::Types::Iterable
- Defined in:
- lib/puppet/pops/types/tree_iterators.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_CONTAINERS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
TypeFactory.variant( PArrayType::DEFAULT, PHashType::DEFAULT, PObjectType::DEFAULT )
Instance Method Summary collapse
-
#each(&block) ⇒ Object
private
Yields each ‘path, value` if the block arity is 2, and only `value` if arity is 1.
-
#initialize(enum, options = EMPTY_HASH) ⇒ TreeIterator
constructor
private
Creates a TreeIterator that by default treats all Array, Hash and Object instances as containers - the ‘containers’ option can be set to a type that denotes which types of values should be treated as containers - a ‘Variant[Array, Hash]` would for instance not treat Object values as containers, whereas just `Object` would only treat objects as containers.
- #reverse_each(&block) ⇒ Object private
- #size ⇒ Object private
- #step(step, &block) ⇒ Object private
- #to_a ⇒ Object private
- #to_array ⇒ Object private
- #unbounded? ⇒ Boolean private
Methods included from Puppet::Pops::Types::Iterable
asserted_iterable, #element_type, #hash_style?, on, unbounded?
Constructor Details
#initialize(enum, options = EMPTY_HASH) ⇒ TreeIterator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a TreeIterator that by default treats all Array, Hash and Object instances as containers - the ‘containers’ option can be set to a type that denotes which types of values should be treated as containers - a ‘Variant[Array, Hash]` would for instance not treat Object values as containers, whereas just `Object` would only treat objects as containers.
Unrecognized options are silently ignored
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/puppet/pops/types/tree_iterators.rb', line 30 def initialize(enum, = EMPTY_HASH) @root = enum @element_t = nil @value_stack = [enum] @indexer_stack = [] @current_path = [] @recursed = false @containers_t = ['container_type'] || DEFAULT_CONTAINERS unless DEFAULT_CONTAINERS.assignable?(@containers_t) raise ArgumentError, _("Only Array, Hash, and Object types can be used as container types. Got %{type}") % { type: @containers_t } end @with_root = extract_option(, 'include_root', true) @with_containers = extract_option(, 'include_containers', true) @with_values = extract_option(, 'include_values', true) @with_root = @with_containers && extract_option(, 'include_root', true) unless @with_containers || @with_values raise ArgumentError, _("Options 'include_containers' and 'include_values' cannot both be false") end @include_refs = !!['include_refs'] end |
Instance Method Details
#each(&block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Yields each ‘path, value` if the block arity is 2, and only `value` if arity is 1
55 56 57 58 59 60 61 62 63 |
# File 'lib/puppet/pops/types/tree_iterators.rb', line 55 def each(&block) loop do if block.arity == 1 yield(self.next) else yield(*self.next) end end end |
#reverse_each(&block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
85 86 87 88 |
# File 'lib/puppet/pops/types/tree_iterators.rb', line 85 def reverse_each(&block) r = Iterator.new(PAnyType::DEFAULT, to_array.reverse_each) block_given? ? r.each(&block) : r end |
#size ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
65 66 67 |
# File 'lib/puppet/pops/types/tree_iterators.rb', line 65 def size raise "Not yet implemented - computes size lazily" end |
#step(step, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
90 91 92 93 |
# File 'lib/puppet/pops/types/tree_iterators.rb', line 90 def step(step, &block) r = StepIterator.new(PAnyType::DEFAULT, self, step) block_given? ? r.each(&block) : r end |
#to_a ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
73 74 75 76 77 78 79 |
# File 'lib/puppet/pops/types/tree_iterators.rb', line 73 def to_a result = [] loop do result << self.next end result end |
#to_array ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
81 82 83 |
# File 'lib/puppet/pops/types/tree_iterators.rb', line 81 def to_array to_a end |
#unbounded? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
69 70 71 |
# File 'lib/puppet/pops/types/tree_iterators.rb', line 69 def unbounded? false end |