Module: MongoTree::ClassMethods

Defined in:
lib/mongo_tree.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_tree(strategy, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mongo_tree.rb', line 18

def acts_as_tree(strategy, options = {})
  @mongo_tree_options = options
  
  case strategy
  when :full_tree
    if options.has_key?(:embeds)
      self.send :include, MongoTree::Strategies::FullTreeRoot
    elsif options.has_key?(:root)
      self.send :include, MongoTree::Strategies::FullTreeNode
    else
      raise 'The full_tree strategy needs to have either the :root or the :embeds class specified'
    end
  when :child_link
    self.send :include, MongoTree::Strategies::ChildLink
  when :parent_link
    self.send :include, MongoTree::Strategies::ParentLink
  when :ancestor_array
    self.send :include, MongoTree::Strategies::AncestorArray
  when :materialized_path
    self.send :include, MongoTree::Strategies::MaterializedPath
  else
    # I guess this is an okay default?
    self.send :include, MongoTree::Strategies::ParentLink
  end
end