Module: MongoTree::Strategies::FullTreeNode::InstanceMethods

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

Instance Method Summary collapse

Instance Method Details

#ancestorsObject



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/mongo_tree/strategies/full_tree_node.rb', line 56

def ancestors
  collected = []
  current = parent

  until current == root
    collected.unshift(current)
    current = current.parent
  end

  collected.unshift(root)
end

#parentObject



31
32
33
# File 'lib/mongo_tree/strategies/full_tree_node.rb', line 31

def parent
  self._parent_document
end

#parent=(target) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/mongo_tree/strategies/full_tree_node.rb', line 35

def parent=(target)
  bson = root_class.collection.find_one(root.id)
  my_bson = nil
  
  modify_children(bson, self) do |parent, found|
    my_bson = found
    parent['children'].delete(found)
  end
  
  modify_children(bson, target) do |parent, found|
    found['children'] << my_bson
  end
  
  root_class.collection.update({'_id' => root.id}, bson)
  root.reload
end

#rootObject



27
28
29
# File 'lib/mongo_tree/strategies/full_tree_node.rb', line 27

def root
  self._root_document
end

#siblingsObject



52
53
54
# File 'lib/mongo_tree/strategies/full_tree_node.rb', line 52

def siblings
  self._parent_document.children.reject{ |n| n.id == self.id }
end