Module: ClosureTree::ActsAsTree

Defined in:
lib/closure_tree/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
# File 'lib/closure_tree/acts_as_tree.rb', line 13

def acts_as_tree(options = {})
  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?
end