module Sequel::Plugins::Tree::InstanceMethods

  1. lib/sequel/plugins/tree.rb
Parent: Tree

Public Instance methods

ancestors ()

Returns list of ancestors, starting from parent until root.

subchild1.ancestors # => [child1, root]
[show source]
# File lib/sequel/plugins/tree.rb, line 85
def ancestors
  node, nodes = self, []
  nodes << node = node.parent while node.parent
  nodes
end
descendants ()

Returns list of ancestors, starting from parent until root.

subchild1.ancestors # => [child1, root]
[show source]
# File lib/sequel/plugins/tree.rb, line 94
def descendants
  nodes = children.dup
  children.each{|child| nodes.concat(child.descendants)}
  nodes 
end
root ()

Returns the root node of the tree that this node descends from. This node is returned if it is a root node itself.

[show source]
# File lib/sequel/plugins/tree.rb, line 102
def root
  ancestors.last || self
end
root? ()

Returns true if this is a root node, false otherwise.

[show source]
# File lib/sequel/plugins/tree.rb, line 107
def root?
  !new? && possible_root?
end
self_and_siblings ()

Returns all siblings and a reference to the current node.

subchild1.self_and_siblings # => [subchild1, subchild2]
[show source]
# File lib/sequel/plugins/tree.rb, line 114
def self_and_siblings
  parent ? parent.children : model.roots
end
siblings ()

Returns all siblings of the current node.

subchild1.siblings # => [subchild2]
[show source]
# File lib/sequel/plugins/tree.rb, line 121
def siblings
  self_and_siblings - [self]
end