Module: IsTree::ActiveRecord::Tree::InstanceMethods
- Defined in:
- lib/is_tree/active_record/tree.rb
Instance Method Summary collapse
- #ancestors ⇒ Object
- #leaf? ⇒ Boolean
-
#root ⇒ Object
Returns the root node of the tree.
- #root? ⇒ Boolean
- #self_and_siblings ⇒ Object
- #siblings ⇒ Object
Instance Method Details
#ancestors ⇒ Object
40 41 42 43 44 |
# File 'lib/is_tree/active_record/tree.rb', line 40 def ancestors node, nodes = self, [] nodes << node = node.parent while node.parent nodes end |
#leaf? ⇒ Boolean
53 54 55 |
# File 'lib/is_tree/active_record/tree.rb', line 53 def leaf? self.children.empty? end |
#root ⇒ Object
Returns the root node of the tree.
47 48 49 50 51 |
# File 'lib/is_tree/active_record/tree.rb', line 47 def root node = self node = node.parent while node.parent node end |
#root? ⇒ Boolean
57 58 59 |
# File 'lib/is_tree/active_record/tree.rb', line 57 def root? self.parent.nil? end |
#self_and_siblings ⇒ Object
65 66 67 |
# File 'lib/is_tree/active_record/tree.rb', line 65 def self_and_siblings self.parent ? self.parent.children : self.class.roots end |
#siblings ⇒ Object
61 62 63 |
# File 'lib/is_tree/active_record/tree.rb', line 61 def siblings self.self_and_siblings.reject{|node| node == self} end |