<commit_before>module Locomotive
  module Extensions
    module Page
      module Tree

        extend ActiveSupport::Concern

        included do
          include ::Mongoid::Tree
          include ::Mongoid::Tree::Ordering
          include PatchedTreeMethods

          ## fields ##
          field :depth, type: Integer, default: 0

          ## callbacks ##
          before_save     :persist_depth
          before_save     :ensure_index_position
          before_destroy  :delete_descendants

          ## indexes ##
          index position: 1
          index depth:    1, position: 1
          index site_id:  1, depth:    1, position: 1

          alias_method_chain :rearrange, :identity_map
          alias_method_chain :rearrange_children, :identity_map
          alias_method_chain :siblings_and_self, :scoping
        end

        module PatchedTreeMethods

          def ancestors
            # https://github.com/benhutton/mongoid-tree/commit/acb6eb0440dc003cd8536cb8cc6ff4b16c9c9402
            super.order_by(:depth.asc)
          end
<commit_msg>delete_descendants no longer work<commit_after>module Locomotive
  module Extensions
    module Page
      module Tree

        extend ActiveSupport::Concern

        included do
          include ::Mongoid::Tree
          include ::Mongoid::Tree::Ordering
          include PatchedTreeMethods

          ## fields ##
          field :depth, type: Integer, default: 0

          ## callbacks ##
          before_save     :persist_depth
          before_save     :ensure_index_position
          before_destroy  :destroy_children

          ## indexes ##
          index position: 1
          index depth:    1, position: 1
          index site_id:  1, depth:    1, position: 1

          alias_method_chain :rearrange, :identity_map
          alias_method_chain :rearrange_children, :identity_map
          alias_method_chain :siblings_and_self, :scoping
        end

        module PatchedTreeMethods

          def ancestors
            # https://github.com/benhutton/mongoid-tree/commit/acb6eb0440dc003cd8536cb8cc6ff4b16c9c9402
            super.order_by(:depth.asc)
          end

{'fraction_non_alphanumeric': 0.06325581395348837, 'fraction_numerical': 0.026976744186046512, 'mean_word_length': 2.021067415730337, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2131002', 'n_tokens_mistral': 634, 'n_tokens_neox': 585, 'n_words': 133}