Sha256: 115de904af9ef35242ebc005e2c2078ac4015edc8cc4918a15bd1e4b8921aacf

Contents?: true

Size: 1.19 KB

Versions: 5

Compression:

Stored size: 1.19 KB

Contents

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,
        :touch,
        :with_advisory_lock
      )

      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?
    rescue StandardError => e
      raise e unless ClosureTree.configuration.database_less
    end

    alias_method :acts_as_tree, :has_closure_tree
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
closure_tree-6.5.0 lib/closure_tree/has_closure_tree.rb
closure_tree-6.4.0 lib/closure_tree/has_closure_tree.rb
closure_tree-6.3.0 lib/closure_tree/has_closure_tree.rb
closure_tree-6.2.0 lib/closure_tree/has_closure_tree.rb
closure_tree-6.1.0 lib/closure_tree/has_closure_tree.rb