<commit_before>require 'ranked-model'

class RankleIndex < ActiveRecord::Base
  belongs_to :indexable, polymorphic: true

  @rankers = {}

  def self.ranks klass, ranker
    @rankers[klass] = ranker
  end

  def self.set_default_position instance
    if @rankers[instance.class] && @rankers[instance.class].strategy
      position = instance.class.ranked.each_with_index { |record, index| break index if @rankers[instance.class].strategy.call(instance, record) } unless @rankers[instance.class].strategy.is_a?(Symbol)
    end
    position = instance.class.count - 1 if position.nil? || position.is_a?(Array)
    instance.rank position
    if @rankers[instance.class] && @rankers[instance.class].strategy.is_a?(Symbol)
      instance.rank @rankers[instance.class].strategy, RankleIndex.where(indexable_name: @rankers[instance.class].strategy).count
    end
  end

  def self.rank instance, name, position
    rankle_index = RankleIndex.where(indexable_name: name.to_s, indexable_id: instance.id, indexable_type: instance.class).first_or_create!
    rankle_index_length = if name == :default
                            RankleIndex.where(indexable_name: name.to_s, indexable_type: instance.class).count
                          else<commit_msg>Removed obsolete require<commit_after>class RankleIndex < ActiveRecord::Base
  belongs_to :indexable, polymorphic: true

  @rankers = {}

  def self.ranks klass, ranker
    @rankers[klass] = ranker
  end

  def self.set_default_position instance
    if @rankers[instance.class] && @rankers[instance.class].strategy
      position = instance.class.ranked.each_with_index { |record, index| break index if @rankers[instance.class].strategy.call(instance, record) } unless @rankers[instance.class].strategy.is_a?(Symbol)
    end
    position = instance.class.count - 1 if position.nil? || position.is_a?(Array)
    instance.rank position
    if @rankers[instance.class] && @rankers[instance.class].strategy.is_a?(Symbol)
      instance.rank @rankers[instance.class].strategy, RankleIndex.where(indexable_name: @rankers[instance.class].strategy).count
    end
  end

  def self.rank instance, name, position
    rankle_index = RankleIndex.where(indexable_name: name.to_s, indexable_id: instance.id, indexable_type: instance.class).first_or_create!
    rankle_index_length = if name == :default
                            RankleIndex.where(indexable_name: name.to_s, indexable_type: instance.class).count
                          else
{'fraction_non_alphanumeric': 0.1087747674888799, 'fraction_numerical': 0.0008087343307723412, 'mean_word_length': 3.9579158316633265, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '4469523', 'n_tokens_mistral': 770, 'n_tokens_neox': 764, 'n_words': 145}