7
8
9
10
11
12
13
14
15
16
17
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/mongo_nested_set.rb', line 7
def acts_as_nested_set(options = {})
options = {
:parent_column => 'parent_id',
:left_column => 'lft',
:right_column => 'rgt',
:dependent => :delete_all, }.merge(options)
if options[:scope].is_a?(Symbol) && options[:scope].to_s !~ /_id$/
options[:scope] = "#{options[:scope]}_id".intern
end
write_inheritable_attribute :acts_as_nested_set_options, options
class_inheritable_reader :acts_as_nested_set_options
unless self.is_a?(ClassMethods)
include Comparable
include Columns
include InstanceMethods
extend Columns
extend ClassMethods
belongs_to :parent, :class_name => self.base_class.to_s,
:foreign_key => parent_column_name
many :children, :class_name => self.base_class.to_s,
:foreign_key => parent_column_name, :order => quoted_left_column_name
attr_accessor :skip_before_destroy
key left_column_name.intern, Integer
key right_column_name.intern, Integer
key parent_column_name.intern, ObjectId
before_create :set_default_left_and_right
before_save :store_new_parent
after_save :move_to_new_parent
before_destroy :destroy_descendants
define_callbacks("before_move", "after_move")
end
end
|