Module: IsTree::ActiveRecord::Tree::InstanceMethods
- Defined in:
- lib/is_tree/active_record/tree.rb
Instance Method Summary collapse
- #ancestors ⇒ Object
- #leaf? ⇒ Boolean
- #root ⇒ Object
- #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
50 51 52 |
# File 'lib/is_tree/active_record/tree.rb', line 50 def leaf? self.children.empty? end |
#root ⇒ Object
46 47 48 |
# File 'lib/is_tree/active_record/tree.rb', line 46 def root self.ancestors.last end |
#root? ⇒ Boolean
54 55 56 |
# File 'lib/is_tree/active_record/tree.rb', line 54 def root? self.parent.nil? end |
#self_and_siblings ⇒ Object
62 63 64 |
# File 'lib/is_tree/active_record/tree.rb', line 62 def self_and_siblings self.parent_id ? self.class.scoped_by_parent_id(self.parent_id) : self.class.roots end |
#siblings ⇒ Object
58 59 60 |
# File 'lib/is_tree/active_record/tree.rb', line 58 def siblings self.self_and_siblings.scoped(:conditions => ["id <> :id",{:id => self.id}]) end |