Module: HasHierarchy::InstanceMethods
- Defined in:
- lib/has_hierarchy.rb
Instance Method Summary collapse
- #child_of?(node) ⇒ Boolean
- #leaf? ⇒ Boolean
- #move_children_to_parent ⇒ Object
- #parent_of?(node) ⇒ Boolean
- #root? ⇒ Boolean
- #sibling_of?(node) ⇒ Boolean
Instance Method Details
#child_of?(node) ⇒ Boolean
118 119 120 |
# File 'lib/has_hierarchy.rb', line 118 def child_of?(node) node.id == parent_id end |
#leaf? ⇒ Boolean
106 107 108 |
# File 'lib/has_hierarchy.rb', line 106 def leaf? children.count == 0 end |
#move_children_to_parent ⇒ Object
126 127 128 129 130 131 |
# File 'lib/has_hierarchy.rb', line 126 def move_children_to_parent children.each do |c| c.parent = self.parent c.save end end |
#parent_of?(node) ⇒ Boolean
114 115 116 |
# File 'lib/has_hierarchy.rb', line 114 def parent_of?(node) node.parent_id == id end |
#root? ⇒ Boolean
110 111 112 |
# File 'lib/has_hierarchy.rb', line 110 def root? parent_id.nil? end |
#sibling_of?(node) ⇒ Boolean
122 123 124 |
# File 'lib/has_hierarchy.rb', line 122 def sibling_of?(node) parent_id == node.parent_id and id != node.id end |