Module: Arboreal::InstanceMethods

Defined in:
lib/arboreal/instance_methods.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) ancestor_ids



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

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

- (Object) ancestors

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

- (Object) descendants

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

- (Object) path_string



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

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

- (Object) root

return the root of the tree



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

def root
  ancestors.first || self
end

- (Object) siblings

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

- (Object) subtree

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