Module Sequel::Plugins::Tree::InstanceMethods
In: lib/sequel/plugins/tree.rb

Methods

Public Instance methods

Returns list of ancestors, starting from parent until root.

  subchild1.ancestors # => [child1, root]

[Source]

    # File lib/sequel/plugins/tree.rb, line 87
87:         def ancestors
88:           node, nodes = self, []
89:           nodes << node = node.parent while node.parent
90:           nodes
91:         end

Returns list of descendants

  node.descendants # => [child1, child2, subchild1_1, subchild1_2, subchild2_1, subchild2_2]

[Source]

     # File lib/sequel/plugins/tree.rb, line 96
 96:         def descendants
 97:           nodes = children.dup
 98:           children.each{|child| nodes.concat(child.descendants)}
 99:           nodes 
100:         end

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

[Source]

     # File lib/sequel/plugins/tree.rb, line 104
104:         def root
105:           ancestors.last || self
106:         end

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

[Source]

     # File lib/sequel/plugins/tree.rb, line 109
109:         def root?
110:           !new? && possible_root?
111:         end

Returns all siblings and a reference to the current node.

  subchild1.self_and_siblings # => [subchild1, subchild2]

[Source]

     # File lib/sequel/plugins/tree.rb, line 116
116:         def self_and_siblings
117:           parent ? parent.children : model.roots
118:         end

Returns all siblings of the current node.

  subchild1.siblings # => [subchild2]

[Source]

     # File lib/sequel/plugins/tree.rb, line 123
123:         def siblings
124:           self_and_siblings - [self]
125:         end

[Validate]