class Puppet::Pops::Types::Iterable::BreadthFirstTreeIterator

Public Class Methods

new(enum, options = EMPTY_HASH) click to toggle source
    # File lib/puppet/pops/types/tree_iterators.rb
195 def initialize(enum, options = EMPTY_HASH)
196   @path_stack = []
197   super
198 end

Public Instance Methods

next() click to toggle source
    # File lib/puppet/pops/types/tree_iterators.rb
200 def next
201   loop do
202     break if @value_stack.empty?
203 
204     # first call
205     if @indexer_stack.empty?
206       @indexer_stack << indexer_on(@root)
207       @recursed = true
208       return [[], @root] if @with_root
209     end
210 
211     begin
212       if @recursed
213         @current_path << nil
214         @recursed = false
215       end
216 
217       idx = @indexer_stack[0].next
218       @current_path[-1] = idx
219       v = @value_stack[0]
220       value = v.is_a?(PuppetObject) ? v.send(idx) : v[idx]
221       indexer = indexer_on(value)
222       if indexer
223         @value_stack << value
224         @indexer_stack << indexer
225         @path_stack << @current_path.dup
226         next unless @with_containers
227       end
228       return [@current_path.dup, value]
229 
230     rescue StopIteration
231       # end of current value's range of content
232       # shift all until out of next values
233       at_the_very_end = false
234       loop do
235         shift_level
236         at_the_very_end = @indexer_stack.empty?
237         break if at_the_very_end || has_next?(@indexer_stack[0])
238       end
239     end
240   end
241   raise StopIteration
242 end

Private Instance Methods

shift_level() click to toggle source
    # File lib/puppet/pops/types/tree_iterators.rb
244 def shift_level
245   @value_stack.shift
246   @indexer_stack.shift
247   @current_path = @path_stack.shift
248   @recursed = true
249 end