Module: ActsAsDAG::Deprecated::ClassMethods
- Defined in:
- lib/acts_as_dag/deprecated.rb
Instance Method Summary collapse
-
#leafs ⇒ Object
Deprecated misspelled method name.
-
#reorganize(categories_to_reorganize = self.all) ⇒ Object
Reorganizes the entire class of records based on their name, first resetting the hierarchy, then reoganizing Can pass a list of categories and only those will be reorganized.
Instance Method Details
#leafs ⇒ Object
Deprecated misspelled method name
6 7 8 |
# File 'lib/acts_as_dag/deprecated.rb', line 6 def leafs leaves end |
#reorganize(categories_to_reorganize = self.all) ⇒ Object
Reorganizes the entire class of records based on their name, first resetting the hierarchy, then reoganizing Can pass a list of categories and only those will be reorganized
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 44 45 46 47 |
# File 'lib/acts_as_dag/deprecated.rb', line 12 def reorganize(categories_to_reorganize = self.all) puts "This method is deprecated and will be removed in a future version" return if categories_to_reorganize.empty? reset_hierarchy(categories_to_reorganize) word_count_groups = categories_to_reorganize.group_by{|category| ActsAsDAG::Deprecated::HelperMethods.word_count(category)}.sort roots_categories = word_count_groups.first[1].dup.sort_by(&:name) # We will build up a list of plinko targets, we start with the group of categories with the shortest word count # Now plinko the next shortest word group into those targets # If we can't plinko one, then it gets added as a root word_count_groups[1..-1].each do |word_count, categories| categories_with_no_parents = [] # Try drop each category into each root categories.sort_by(&:name).each do |category| ActiveRecord::Base.benchmark "Analyze #{category.name}" do suitable_parent = false roots_categories.each do |root| suitable_parent = true if ActsAsDAG::Deprecated::HelperMethods.plinko(root, category) end unless suitable_parent ActiveRecord::Base.logger.info { "Plinko couldn't find a suitable parent for #{category.name}" } categories_with_no_parents << category end end end # Add all categories from this group without suitable parents to the roots if categories_with_no_parents.present? ActiveRecord::Base.logger.info { "Adding #{categories_with_no_parents.collect(&:name).join(', ')} to roots" } roots_categories.concat categories_with_no_parents end end end |