Class: CollectiveIdea::Acts::NestedSet::Iterator
- Inherits:
-
Object
- Object
- CollectiveIdea::Acts::NestedSet::Iterator
- Defined in:
- lib/plugins/awesome_nested_set/lib/awesome_nested_set/iterator.rb
Instance Attribute Summary (collapse)
-
- (Object) objects
readonly
Returns the value of attribute objects.
Instance Method Summary (collapse)
- - (Object) each_with_level
-
- (Iterator) initialize(objects)
constructor
A new instance of Iterator.
Constructor Details
- (Iterator) initialize(objects)
Returns a new instance of Iterator
7 8 9 |
# File 'lib/plugins/awesome_nested_set/lib/awesome_nested_set/iterator.rb', line 7 def initialize(objects) @objects = objects end |
Instance Attribute Details
- (Object) objects (readonly)
Returns the value of attribute objects
5 6 7 |
# File 'lib/plugins/awesome_nested_set/lib/awesome_nested_set/iterator.rb', line 5 def objects @objects end |
Instance Method Details
- (Object) each_with_level
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/plugins/awesome_nested_set/lib/awesome_nested_set/iterator.rb', line 11 def each_with_level path = [nil] objects.each do |o| if o.parent_id != path.last # we are on a new level, did we descend or ascend? if path.include?(o.parent_id) # remove wrong tailing paths elements path.pop while path.last != o.parent_id else path << o.parent_id end end yield(o, path.length - 1) end end |