Module: ActiveRecord::Acts::Tree::InstanceMethods
- Defined in:
- lib/active_record/acts/tree.rb
Instance Method Summary collapse
-
#ancestors ⇒ Object
Returns list of ancestors, starting from parent until root.
- #root ⇒ Object
- #self_and_siblings ⇒ Object
- #siblings ⇒ Object
Instance Method Details
#ancestors ⇒ Object
Returns list of ancestors, starting from parent until root.
subchild1.ancestors # => [child1, root]
68 69 70 71 72 |
# File 'lib/active_record/acts/tree.rb', line 68 def ancestors node, nodes = self, [] nodes << node = node.parent until not node.has_parent? nodes end |
#root ⇒ Object
74 75 76 77 78 |
# File 'lib/active_record/acts/tree.rb', line 74 def root node = self node = node.parent until not node.has_parent? node end |
#self_and_siblings ⇒ Object
84 85 86 |
# File 'lib/active_record/acts/tree.rb', line 84 def self_and_siblings has_parent? ? parent.children : self.class.roots end |
#siblings ⇒ Object
80 81 82 |
# File 'lib/active_record/acts/tree.rb', line 80 def siblings self_and_siblings - [self] end |