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 94
94:         def ancestors
95:           node, nodes = self, []
96:           nodes << node = node.parent while node.parent
97:           nodes
98:         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 103
103:         def descendants
104:           nodes = children.dup
105:           children.each{|child| nodes.concat(child.descendants)}
106:           nodes 
107:         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 111
111:         def root
112:           ancestors.last || self
113:         end

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

[Source]

     # File lib/sequel/plugins/tree.rb, line 116
116:         def root?
117:           !new? && possible_root?
118:         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 123
123:         def self_and_siblings
124:           parent ? parent.children : model.roots
125:         end

Returns all siblings of the current node.

  subchild1.siblings # => [subchild2]

[Source]

     # File lib/sequel/plugins/tree.rb, line 130
130:         def siblings
131:           self_and_siblings - [self]
132:         end

[Validate]