<commit_before>class SequenceManager
  def initialize(klass, options)
    @managed  = klass

    @start    = options[:start]
    @usage    = options[:usage]
    @force    = options[:force]
    @column   = options[:column]
    @readonly = options[:readonly]
  end

  def last_numbered_record
    @managed
      .where.not(@column => nil)
      .reorder("LENGTH(#{@column}) DESC, #{@column} DESC")
      .first
  end

  def next_number
    return sequence.next_value if sequence

    last = last_numbered_record
    return @start if last.blank?

    number_of(last).succ
  end

  def unique_predictable
    last  = last_numbered_record
    value = @start
    value = number_of(last).succ unless last.blank?
    value = value.succ while @managed.find_by(@column => value)
    value
  end

  def load_predictable_into(record)
    return true if @force && number_of(record).present?
    set_number(record, unique_predictable)
    true
  end

  def load_reliable_into(record)
    return true if !@force && number_of(record)

    return load_predictable_into(record) unless sequence

    value = sequence.next_value!
    value = sequence.next_value! while @managed.find_by(@column => value)
    record.send(:"#{@column}=", value)
    true
  end

  def set_number(record, value)
    record.send(:"#{@column}=", value)
  end

  def number_of(record)
    record.send(@column)
  end

  def sequence<commit_msg>Fixed an obscure problem that happened when you destroyed your DB without reloading class code but that happened during  because there's a sequenced-model use in one of the migrations.<commit_after>class SequenceManager
  def initialize(klass, options)
    @managed  = klass

    @start    = options[:start]
    @usage    = options[:usage]
    @force    = options[:force]
    @column   = options[:column]
    @readonly = options[:readonly]
  end

  def last_numbered_record
    @managed
      .where.not(@column => nil)
      .reorder("LENGTH(#{@column}) DESC, #{@column} DESC")
      .first
  end

  def next_number
    return sequence.next_value if sequence

    last = last_numbered_record
    return @start if last.blank?

    number_of(last).succ
  end

  def unique_predictable
    last  = last_numbered_record
    value = @start
    value = number_of(last).succ unless last.blank?
    value = value.succ while @managed.find_by(@column => value)
    value
  end

  def load_predictable_into(record)
    return true if @force && number_of(record).present?
    set_number(record, unique_predictable)
    true
  end

  def load_reliable_into(record)
    return true if !@force && number_of(record)

    return load_predictable_into(record) unless sequence

    value = sequence.next_value!
    value = sequence.next_value! while @managed.find_by(@column => value)
    record.send(:"#{@column}=", value)
    true
  end

  def set_number(record, value)
    record.send(:"#{@column}=", value)
  end

  def number_of(record)
    record.send(@column)
  end

  def sequence
    @sequence = @sequence && Sequence.find_by(id: @sequence.id)
{'fraction_non_alphanumeric': 0.10484668644906034, 'fraction_numerical': 0.0, 'mean_word_length': 3.3591954022988504, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '2113829', 'n_tokens_mistral': 973, 'n_tokens_neox': 933, 'n_words': 241}