Module: MongoTree::Strategies::AncestorArray::InstanceMethods

Defined in:
lib/mongo_tree/strategies/ancestor_array.rb

Instance Method Summary collapse

Instance Method Details

#ancestorsObject



44
45
46
# File 'lib/mongo_tree/strategies/ancestor_array.rb', line 44

def ancestors
  self.ancestor_ids.map{ |id| self.class.first(path_attribute => id) }
end

#depthObject



36
37
38
# File 'lib/mongo_tree/strategies/ancestor_array.rb', line 36

def depth
  ancestor_ids.length
end

#descendantsObject



48
49
50
# File 'lib/mongo_tree/strategies/ancestor_array.rb', line 48

def descendants
  self.class.all(:ancestor_ids.all => self.ancestor_ids << self.send(path_attribute))
end

#rootObject



32
33
34
# File 'lib/mongo_tree/strategies/ancestor_array.rb', line 32

def root
  self.class.first(path_attribute => self.ancestor_ids.first)
end

#siblingsObject



40
41
42
# File 'lib/mongo_tree/strategies/ancestor_array.rb', line 40

def siblings
  self.class.all(:parent_id => self.parent_id, path_attribute.ne => self.send(path_attribute))
end