@@ -6,45 +6,44 @@ module Model
66
77 included do
88 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
1212
13+ # TODO, remove when activerecord 3.2 support is dropped
1314 attr_accessible :parent if _ct . use_attr_accessible?
1415
1516 order_by_generations = "#{ _ct . quoted_hierarchy_table_name } .generations asc"
1617
1718 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 )
2223
2324 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 )
2728
2829 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 )
3233
3334 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 )
3738
3839 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 )
4243 end
4344
4445 # Delegate to the Support instance on the class:
45- def _ct
46- self . class . _ct
47- end
46+ delegate :_ct , to : :class
4847
4948 # Returns true if this node has no parents.
5049 def root?
@@ -76,7 +75,7 @@ def depth
7675 ancestors . size
7776 end
7877
79- alias :level :depth
78+ alias_method :level , :depth
8079
8180 def ancestors
8281 without_self ( self_and_ancestors )
@@ -94,7 +93,7 @@ def self_and_ancestors_ids
9493 # to the +name_column+.
9594 # (so child.ancestry_path == +%w{grandparent parent child}+
9695 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 }
9897 end
9998
10099 def child_ids
0 commit comments