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 85
85:         def ancestors
86:           node, nodes = self, []
87:           nodes << node = node.parent while node.parent
88:           nodes
89:         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 94
94:         def descendants
95:           nodes = children.dup
96:           children.each{|child| nodes.concat(child.descendants)}
97:           nodes 
98:         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 102
102:         def root
103:           ancestors.last || self
104:         end

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

[Source]

     # File lib/sequel/plugins/tree.rb, line 107
107:         def root?
108:           !new? && possible_root?
109:         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 114
114:         def self_and_siblings
115:           parent ? parent.children : model.roots
116:         end

Returns all siblings of the current node.

  subchild1.siblings # => [subchild2]

[Source]

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

[Validate]