Module: MongoTree::Strategies::ParentLink::InstanceMethods

Defined in:
lib/mongo_tree/strategies/parent_link.rb

Instance Method Summary collapse

Instance Method Details

#descendantsObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mongo_tree/strategies/parent_link.rb', line 27

def descendants
  collected = []
  nodes = [self]

  until nodes.empty?
    current = nodes.shift
    current_children = self.class.all(:parent_id => current.id)
    nodes += current_children
    collected += current_children
  end

  collected
end

#siblingsObject



23
24
25
# File 'lib/mongo_tree/strategies/parent_link.rb', line 23

def siblings
  self.class.all(:parent_id => self.parent_id, :id.ne => self.id)
end