module Mongoid::Tree::RationalNumbering::ClassMethods
Attributes
Public Instance Methods
# File lib/mongoid/tree/rational_numbering.rb, line 82 def auto_tree_timestamping @auto_tree_timestamping.nil? ? true : @auto_tree_timestamping end
Set options for rational numbers
@param opts [Hash] a hash of options
:auto_tree_timestamping (true/false) Per default timestamps are only updated on the a node that is changed, and not siblings that are moved/shifted due to changes on a given node. Usually the tree position of a document does not give information about changes to the content of the document. This behaviour can be changed through the option ‘:auto_tree_timestamping’.
# File lib/mongoid/tree/rational_numbering.rb, line 97 def rational_number_options(opts) if !opts[:auto_tree_timestamping].nil? @auto_tree_timestamping = !!opts[:auto_tree_timestamping] else @auto_tree_timestamping = true end end
Force all rational number keys to update
Can be used to remove any “gaps” that are in a tree
For large collections, this uses a lot of resources, and should probably be used in a backround job on production sites. As a rational tree works just fine even if there are missing items, this shouldn’t be necessary to do that often.
# File lib/mongoid/tree/rational_numbering.rb, line 116 def rekey_all! # rekey keys for each root. will do children _pos = 1 root_rational = RationalNumber.new self.roots.each do |root| new_rational = root_rational.child_from_position(_pos) if new_rational != root.rational_number root.move_to_rational_number(new_rational.nv, new_rational.dv, {:force => true}) root.save_with_force_rational_numbers! # root.reload # Should caller be responsible for reloading? end root.rekey_children _pos += 1 end end