Module: Arboreal::InstanceMethods
- Defined in:
- lib/arboreal/instance_methods.rb
Instance Method Summary collapse
- #ancestor_ids ⇒ Object
-
#ancestors ⇒ Object
return a scope matching all ancestors of this node.
-
#descendants ⇒ Object
return a scope matching all descendants of this node.
- #path_string ⇒ Object
-
#root ⇒ Object
return the root of the tree.
-
#siblings ⇒ Object
return a scope matching all siblings of this node (NOT including the node itself).
-
#subtree ⇒ Object
return a scope matching all descendants of this node, AND the node itself.
Instance Method Details
#ancestor_ids ⇒ Object
10 11 12 |
# File 'lib/arboreal/instance_methods.rb', line 10 def ancestor_ids ancestry_string.sub(/^-/, "").split("-").map { |x| x.to_i } end |
#ancestors ⇒ Object
return a scope matching all ancestors of this node
15 16 17 |
# File 'lib/arboreal/instance_methods.rb', line 15 def ancestors model_base_class.scoped(:conditions => ancestor_conditions, :order => :ancestry_string) end |
#descendants ⇒ Object
return a scope matching all descendants of this node
20 21 22 |
# File 'lib/arboreal/instance_methods.rb', line 20 def descendants model_base_class.scoped(:conditions => descendant_conditions) end |
#path_string ⇒ Object
6 7 8 |
# File 'lib/arboreal/instance_methods.rb', line 6 def path_string "#{ancestry_string}#{id}-" end |
#root ⇒ Object
return the root of the tree
35 36 37 |
# File 'lib/arboreal/instance_methods.rb', line 35 def root ancestors.first || self end |
#siblings ⇒ Object
return a scope matching all siblings of this node (NOT including the node itself)
30 31 32 |
# File 'lib/arboreal/instance_methods.rb', line 30 def siblings model_base_class.scoped(:conditions => sibling_conditions) end |
#subtree ⇒ Object
return a scope matching all descendants of this node, AND the node itself
25 26 27 |
# File 'lib/arboreal/instance_methods.rb', line 25 def subtree model_base_class.scoped(:conditions => subtree_conditions) end |