module Sequel::Plugins::Tree::InstanceMethods
def ancestors
Returns list of ancestors, starting from parent until root.
def ancestors node, nodes = self, [] nodes << node = node.parent while node.parent nodes end
def descendants
Returns list of ancestors, starting from parent until root.
def descendants nodes = children.dup nodes.each{|child| nodes.concat(child.descendants)} nodes end
def root
Returns the root node of the tree that this node descends from
def root ancestors.last || self end
def root?
def root? !new? && self[model.parent_column].nil? end
def self_and_siblings
Returns all siblings and a reference to the current node.
def self_and_siblings parent ? parent.children : model.roots end
def siblings
Returns all siblings of the current node.
def siblings self_and_siblings - [self] end