Class: Puppet::Pops::Types::Iterable::BreadthFirstTreeIterator Private

Inherits:
TreeIterator show all
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

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) ⇒ BreadthFirstTreeIterator

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.

Returns a new instance of BreadthFirstTreeIterator.



195
196
197
198
# File 'lib/puppet/pops/types/tree_iterators.rb', line 195

def initialize(enum, options = EMPTY_HASH)
  @path_stack = []
  super
end

Instance Method Details

#nextObject

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.

Raises:

  • (StopIteration)


200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/puppet/pops/types/tree_iterators.rb', line 200

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[0].next
      @current_path[-1] = idx
      v = @value_stack[0]
      value = v.is_a?(PuppetObject) ? v.send(idx) : v[idx]
      indexer = indexer_on(value)
      if indexer
        @value_stack << value
        @indexer_stack << indexer
        @path_stack << @current_path.dup
        next unless @with_containers
      end
      return [@current_path.dup, value]

    rescue StopIteration
      # end of current value's range of content
      # shift all until out of next values
      at_the_very_end = false
      loop do
        shift_level
        at_the_very_end = @indexer_stack.empty?
        break if at_the_very_end || has_next?(@indexer_stack[0])
      end
    end
  end
  raise StopIteration
end