Class: Puppet::Pops::Types::Iterable::DepthFirstTreeIterator Private
- Inherits:
-
TreeIterator
- Object
- TreeIterator
- Puppet::Pops::Types::Iterable::DepthFirstTreeIterator
- 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.
Constant Summary
Constants inherited from TreeIterator
TreeIterator::DEFAULT_CONTAINERS
Instance Method Summary collapse
-
#initialize(enum, options = EMPTY_HASH) ⇒ DepthFirstTreeIterator
constructor
private
Creates a DepthFirstTreeIterator 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.
- #next ⇒ Object private
Methods inherited from TreeIterator
#each, #reverse_each, #size, #step, #to_a, #to_array, #unbounded?
Methods included from Puppet::Pops::Types::Iterable
asserted_iterable, #each, #element_type, #hash_style?, on, #reverse_each, #step, #to_a, unbounded?, #unbounded?
Constructor Details
#initialize(enum, options = EMPTY_HASH) ⇒ DepthFirstTreeIterator
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 DepthFirstTreeIterator 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.
135 136 137 |
# File 'lib/puppet/pops/types/tree_iterators.rb', line 135 def initialize(enum, = EMPTY_HASH) super end |
Instance Method Details
#next ⇒ 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.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/puppet/pops/types/tree_iterators.rb', line 139 def next loop do break if @value_stack.empty? # first call if @indexer_stack.empty? @indexer_stack << indexer_on(@root) @recursed = true return [[], @root] if @with_root end begin if @recursed @current_path << nil @recursed = false end idx = @indexer_stack[-1].next @current_path[-1] = idx v = @value_stack[-1] value = v.is_a?(PuppetObject) ? v.send(idx) : v[idx] indexer = indexer_on(value) if indexer # recurse @recursed = true @value_stack << value @indexer_stack << indexer redo unless @with_containers else redo unless @with_values end return [@current_path.dup, value] rescue StopIteration # end of current value's range of content # pop all until out of next values at_the_very_end = false loop do pop_level at_the_very_end = @indexer_stack.empty? break if at_the_very_end || has_next?(@indexer_stack[-1]) end end end raise StopIteration end |