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 86
86:         def ancestors
87:           node, nodes = self, []
88:           nodes << node = node.parent while node.parent
89:           nodes
90:         end

Returns list of ancestors, starting from parent until root.

  subchild1.ancestors # => [child1, root]

[Source]

    # File lib/sequel/plugins/tree.rb, line 95
95:         def descendants
96:           nodes = children.dup
97:           nodes.each{|child| nodes.concat(child.descendants)}
98:           nodes 
99:         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 103
103:         def root
104:           ancestors.last || self
105:         end

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

[Source]

     # File lib/sequel/plugins/tree.rb, line 108
108:         def root?
109:           !new? && self[model.parent_column].nil?
110:         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 115
115:         def self_and_siblings
116:           parent ? parent.children : model.roots
117:         end

Returns all siblings of the current node.

  subchild1.siblings # => [subchild2]

[Source]

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

[Validate]