class Puppet::Pops::Types::Iterable::DepthFirstTreeIterator
Public Class Methods
new(enum, options = EMPTY_HASH)
click to toggle source
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.
@param [Hash] options the options @option options [PTypeType] :containers ('Variant[Hash, Array, Object]') The type(s) that should be treated as containers @option options [Boolean] :with_root ('true') If the root container itself should be included in the iteration
Calls superclass method
Puppet::Pops::Types::Iterable::TreeIterator::new
# File lib/puppet/pops/types/tree_iterators.rb 137 def initialize(enum, options = EMPTY_HASH) 138 super 139 end
Public Instance Methods
next()
click to toggle source
# File lib/puppet/pops/types/tree_iterators.rb 141 def next 142 loop do 143 break if @value_stack.empty? 144 145 # first call 146 if @indexer_stack.empty? 147 @indexer_stack << indexer_on(@root) 148 @recursed = true 149 return [[], @root] if @with_root 150 end 151 152 begin 153 if @recursed 154 @current_path << nil 155 @recursed = false 156 end 157 idx = @indexer_stack[-1].next 158 @current_path[-1] = idx 159 v = @value_stack[-1] 160 value = v.is_a?(PuppetObject) ? v.send(idx) : v[idx] 161 indexer = indexer_on(value) 162 if indexer 163 # recurse 164 @recursed = true 165 @value_stack << value 166 @indexer_stack << indexer 167 redo unless @with_containers 168 else 169 redo unless @with_values 170 end 171 return [@current_path.dup, value] 172 173 rescue StopIteration 174 # end of current value's range of content 175 # pop all until out of next values 176 at_the_very_end = false 177 loop do 178 pop_level 179 at_the_very_end = @indexer_stack.empty? 180 break if at_the_very_end || has_next?(@indexer_stack[-1]) 181 end 182 end 183 end 184 raise StopIteration 185 end
Private Instance Methods
pop_level()
click to toggle source
# File lib/puppet/pops/types/tree_iterators.rb 187 def pop_level 188 @value_stack.pop 189 @indexer_stack.pop 190 @current_path.pop 191 end