Module: DataMapper::Is::Tree::InstanceMethods
Public Visibility
Public Instance Method Summary
| #ancestors |
Returns list of ancestors, starting with the root. |
|---|---|
| #generation #self_and_siblings |
Returns all children of the current node’s parent. |
| #root |
Returns the root node of the current node’s tree. |
| #siblings |
Returns all siblings of the current node. |
Public Instance Method Details
ancestors
public
ancestors
Returns list of ancestors, starting with the root.
grandchild1.ancestors # => [root, child]
[View source]
93 94 95 96 97 98 99 100 101
# File 'dm-more/dm-is-tree/lib/dm-is-tree/is/tree.rb', line 93 def ancestors node, nodes = self, [] nodes << node = node.parent while node.parent nodes.reverse end
generation
public
generation
Also known as: self_and_siblings
Returns all children of the current node’s parent.
grandchild1.generation # => [grandchild1, grandchild2]
[View source]
118 119 120 121 122 123 124
# File 'dm-more/dm-is-tree/lib/dm-is-tree/is/tree.rb', line 118 def generation parent ? parent.children : self.class.roots end
root
public
root
Returns the root node of the current node’s tree.
grandchild1.root # => root
[View source]
102 103 104 105 106 107 108 109 110
# File 'dm-more/dm-is-tree/lib/dm-is-tree/is/tree.rb', line 102 def root node = self node = node.parent while node.parent node end
siblings
public
siblings
Returns all siblings of the current node.
grandchild1.siblings # => [grandchild2]
[View source]
111 112 113 114 115 116 117
# File 'dm-more/dm-is-tree/lib/dm-is-tree/is/tree.rb', line 111 def siblings generation - [self] end