@@ -6,45 +6,44 @@ module Model
6
6
7
7
included do
8
8
belongs_to :parent ,
9
- :class_name => _ct . model_class . to_s ,
10
- :foreign_key => _ct . parent_column_name ,
11
- :inverse_of => :children
9
+ class_name : _ct . model_class . to_s ,
10
+ foreign_key : _ct . parent_column_name ,
11
+ inverse_of : :children
12
12
13
+ # TODO, remove when activerecord 3.2 support is dropped
13
14
attr_accessible :parent if _ct . use_attr_accessible?
14
15
15
16
order_by_generations = "#{ _ct . quoted_hierarchy_table_name } .generations asc"
16
17
17
18
has_many :children , *_ct . has_many_with_order_option (
18
- : class_name => _ct . model_class . to_s ,
19
- : foreign_key => _ct . parent_column_name ,
20
- : dependent => _ct . options [ :dependent ] ,
21
- : inverse_of => :parent )
19
+ class_name : _ct . model_class . to_s ,
20
+ foreign_key : _ct . parent_column_name ,
21
+ dependent : _ct . options [ :dependent ] ,
22
+ inverse_of : :parent )
22
23
23
24
has_many :ancestor_hierarchies , *_ct . has_many_without_order_option (
24
- : class_name => _ct . hierarchy_class_name ,
25
- : foreign_key => " descendant_id" ,
26
- : order => order_by_generations )
25
+ class_name : _ct . hierarchy_class_name ,
26
+ foreign_key : ' descendant_id' ,
27
+ order : order_by_generations )
27
28
28
29
has_many :self_and_ancestors , *_ct . has_many_without_order_option (
29
- : through => :ancestor_hierarchies ,
30
- : source => :ancestor ,
31
- : order => order_by_generations )
30
+ through : :ancestor_hierarchies ,
31
+ source : :ancestor ,
32
+ order : order_by_generations )
32
33
33
34
has_many :descendant_hierarchies , *_ct . has_many_without_order_option (
34
- : class_name => _ct . hierarchy_class_name ,
35
- : foreign_key => " ancestor_id" ,
36
- : order => order_by_generations )
35
+ class_name : _ct . hierarchy_class_name ,
36
+ foreign_key : ' ancestor_id' ,
37
+ order : order_by_generations )
37
38
38
39
has_many :self_and_descendants , *_ct . has_many_with_order_option (
39
- : through => :descendant_hierarchies ,
40
- : source => :descendant ,
41
- : order => order_by_generations )
40
+ through : :descendant_hierarchies ,
41
+ source : :descendant ,
42
+ order : order_by_generations )
42
43
end
43
44
44
45
# Delegate to the Support instance on the class:
45
- def _ct
46
- self . class . _ct
47
- end
46
+ delegate :_ct , to : :class
48
47
49
48
# Returns true if this node has no parents.
50
49
def root?
@@ -76,7 +75,7 @@ def depth
76
75
ancestors . size
77
76
end
78
77
79
- alias :level :depth
78
+ alias_method :level , :depth
80
79
81
80
def ancestors
82
81
without_self ( self_and_ancestors )
@@ -94,7 +93,7 @@ def self_and_ancestors_ids
94
93
# to the +name_column+.
95
94
# (so child.ancestry_path == +%w{grandparent parent child}+
96
95
def ancestry_path ( to_s_column = _ct . name_column )
97
- self_and_ancestors . reverse . collect { |n | n . send to_s_column . to_sym }
96
+ self_and_ancestors . reverse . map { |n | n . send to_s_column . to_sym }
98
97
end
99
98
100
99
def child_ids
0 commit comments