-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy pathhas_closure_tree.rb
43 lines (37 loc) · 1.31 KB
/
has_closure_tree.rb
1
2
3
4
5
6
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
module ClosureTree
module HasClosureTree
def has_closure_tree(options = {})
options.assert_valid_keys(
:parent_column_name,
:dependent,
:hierarchy_class_name,
:hierarchy_table_name,
:name_column,
:order,
:dont_order_roots,
:numeric_order,
:touch,
:with_advisory_lock,
:counter_cache
)
class_attribute :_ct
self._ct = ClosureTree::Support.new(self, options)
# Auto-inject the hierarchy table
# See https://github.com/patshaughnessy/class_factory/blob/master/lib/class_factory/class_factory.rb
class_attribute :hierarchy_class
self.hierarchy_class = _ct.hierarchy_class_for_model
# tests fail if you include Model before HierarchyMaintenance wtf
include ClosureTree::HierarchyMaintenance
include ClosureTree::Model
include ClosureTree::Finders
include ClosureTree::HashTree
include ClosureTree::Digraphs
include ClosureTree::DeterministicOrdering if _ct.order_option?
include ClosureTree::NumericDeterministicOrdering if _ct.order_is_numeric?
connection_pool.release_connection
rescue StandardError => e
raise e unless ClosureTree.configuration.database_less
end
alias_method :acts_as_tree, :has_closure_tree
end
end