Module: MongoTree::Strategies::ChildLink::InstanceMethods

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

Instance Method Summary collapse

Instance Method Details

#descendantsObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mongo_tree/strategies/child_link.rb', line 38

def descendants
  collected = []
  nodes = self.children

  until nodes.empty?
    current = nodes.shift
    collected << current
    nodes += current.children
  end

  collected
end

#parentObject



23
24
25
# File 'lib/mongo_tree/strategies/child_link.rb', line 23

def parent
  @parent ||= self.class.find(self.child_id)
end

#parent=(node) ⇒ Object



27
28
29
30
31
# File 'lib/mongo_tree/strategies/child_link.rb', line 27

def parent=(node)
  @parent = node
  self.child_id = node.id
  save if changed?
end

#siblingsObject



33
34
35
36
# File 'lib/mongo_tree/strategies/child_link.rb', line 33

def siblings
  return nil if parent.nil?
  parent.children.reject{ |node| node == self }
end