Module: Arboreal::InstanceMethods

Defined in:
lib/arboreal/instance_methods.rb

Instance Method Summary collapse

Instance Method Details

#ancestor_idsObject



10
11
12
# File 'lib/arboreal/instance_methods.rb', line 10

def ancestor_ids
  ancestry_string.sub(/^-/, "").split("-").map { |x| x.to_i }
end

#ancestorsObject

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

#descendantsObject

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_stringObject



6
7
8
# File 'lib/arboreal/instance_methods.rb', line 6

def path_string
  "#{ancestry_string}#{id}-"
end

#rootObject

return the root of the tree



35
36
37
# File 'lib/arboreal/instance_methods.rb', line 35

def root
  ancestors.first || self
end

#siblingsObject

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

#subtreeObject

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