module Mongestry::ClassMethods
Public Instance Methods
after_depth(depth)
click to toggle source
Return nodes that are deeper than depth (node.depth > depth)
# File lib/mongestry.rb, line 208 def after_depth depth self.where(persisted_depth: {"$gt" => depth}) end
ancestors_of(node)
click to toggle source
Ancestors of node, node can be either a record or an id
# File lib/mongestry.rb, line 163 def ancestors_of node node.ancestors end
at_depth(depth)
click to toggle source
Return nodes that are at depth (node.depth == depth)
# File lib/mongestry.rb, line 198 def at_depth depth self.where(persisted_depth: depth) end
before_depth(depth)
click to toggle source
Return nodes that are less deep than depth (node.depth < depth)
# File lib/mongestry.rb, line 188 def before_depth depth self.where(persisted_depth: {"$lt" => depth}) end
children_of(node)
click to toggle source
Children of node, node can be either a record or an id
# File lib/mongestry.rb, line 168 def children_of node node.children end
descendants_of(node)
click to toggle source
Descendants of node, node can be either a record or an id
# File lib/mongestry.rb, line 173 def descendants_of node node.descendants end
from_depth(depth)
click to toggle source
Return nodes starting from a certain depth (node.depth >= depth)
# File lib/mongestry.rb, line 203 def from_depth depth self.where(persisted_depth: {"$gte" => depth}) end
object_for(identifier)
click to toggle source
# File lib/mongestry.rb, line 145 def object_for identifier return nil if identifier == "" case identifier when BSON::ObjectId self.find identifier when String self.find(BSON::ObjectId.from_string(identifier)) when self identifier end end
roots()
click to toggle source
Root nodes
# File lib/mongestry.rb, line 158 def roots self.where(ancestry: nil) end
siblings_of(node)
click to toggle source
Siblings of node, node can be either a record or an id
# File lib/mongestry.rb, line 183 def siblings_of node node.siblings end
subtree_of(node)
click to toggle source
Subtree of node, node can be either a record or an id
# File lib/mongestry.rb, line 178 def subtree_of node node.subtree end
to_depth(depth)
click to toggle source
Return nodes up to a certain depth (node.depth <= depth)
# File lib/mongestry.rb, line 193 def to_depth depth self.where(persisted_depth: {"$lte" => depth}) end