class CollectiveIdea::Acts::NestedSet::Iterator
Attributes
objects[R]
Public Class Methods
new(objects)
click to toggle source
# File lib/awesome_nested_set/iterator.rb 7 def initialize(objects) 8 @objects = objects 9 end
Public Instance Methods
each_with_level() { |o, length - 1| ... }
click to toggle source
# File lib/awesome_nested_set/iterator.rb 11 def each_with_level 12 path = [nil] 13 objects.each do |o| 14 if o.parent_id != path.last 15 # we are on a new level, did we descend or ascend? 16 if path.include?(o.parent_id) 17 # remove wrong tailing paths elements 18 path.pop while path.last != o.parent_id 19 else 20 path << o.parent_id 21 end 22 end 23 yield(o, path.length - 1) 24 end 25 end