class Puppet::Pops::Types::Iterable::BreadthFirstTreeIterator
Public Class Methods
new(enum, options = EMPTY_HASH)
click to toggle source
Calls superclass method
Puppet::Pops::Types::Iterable::TreeIterator::new
# File lib/puppet/pops/types/tree_iterators.rb 196 def initialize(enum, options = EMPTY_HASH) 197 @path_stack = [] 198 super 199 end
Public Instance Methods
next()
click to toggle source
# File lib/puppet/pops/types/tree_iterators.rb 201 def next 202 loop do 203 break if @value_stack.empty? 204 205 # first call 206 if @indexer_stack.empty? 207 @indexer_stack << indexer_on(@root) 208 @recursed = true 209 return [[], @root] if @with_root 210 end 211 212 begin 213 if @recursed 214 @current_path << nil 215 @recursed = false 216 end 217 218 idx = @indexer_stack[0].next 219 @current_path[-1] = idx 220 v = @value_stack[0] 221 value = v.is_a?(PuppetObject) ? v.send(idx) : v[idx] 222 indexer = indexer_on(value) 223 if indexer 224 @value_stack << value 225 @indexer_stack << indexer 226 @path_stack << @current_path.dup 227 next unless @with_containers 228 end 229 return [@current_path.dup, value] 230 231 rescue StopIteration 232 # end of current value's range of content 233 # shift all until out of next values 234 at_the_very_end = false 235 loop do 236 shift_level 237 at_the_very_end = @indexer_stack.empty? 238 break if at_the_very_end || has_next?(@indexer_stack[0]) 239 end 240 end 241 end 242 raise StopIteration 243 end
Private Instance Methods
shift_level()
click to toggle source
# File lib/puppet/pops/types/tree_iterators.rb 245 def shift_level 246 @value_stack.shift 247 @indexer_stack.shift 248 @current_path = @path_stack.shift 249 @recursed = true 250 end