Module: MongoMapper::Acts::Tree::InitializerMethods

Defined in:
lib/mongo_mapper_acts_as_tree.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_tree(options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mongo_mapper_acts_as_tree.rb', line 13

def acts_as_tree(options = {})
  options = {
    :parent_id_field => "parent_id",
    :path_field      => "path",
    :depth_field     => "depth"
  }.merge(options)
  
  write_inheritable_attribute :acts_as_tree_options, options
  class_inheritable_reader :acts_as_tree_options
  
  include InstanceMethods
  include Fields
  extend Fields
  extend ClassMethods
  
  key parent_id_field,  ObjectId
  key path_field,       Array,  :default => [], :index => true
  key depth_field,      Integer, :default => 0
  
  after_save      :move_children
  validate        :will_save_tree
  before_destroy  :destroy_descendants
end