<commit_before>require 'pstore'

class Base
  class << self
    def find(id)
      db.transaction(true) do
        db[db_id(id)]
      end
    end

    def all
      db.transaction(true) do
        db.roots
          .select { |key| key.start_with?(self.name) }
          .map { |key| db[key] }
      end
    end

    def db
      @db ||= PStore.new("db.pstore")
    end

    def db_id(base)
      "#{self.name}_#{base}"
    end
  end


  def save
    self.class.db.transaction do |db|
      db[db_id] = self
    end
  end


  def db_id
    self.class.db_id(id)
  end
end<commit_msg>Models' indexes are auto assigned with autoincrement on save<commit_after>require 'pstore'

class Base
  class << self
    def find(id)
      db.transaction(true) do
        db[db_id(id)]
      end
    end

    def all
      db.transaction(true) do
        db.roots
          .select { |key| key.start_with?(self.name) }
          .map { |key| db[key] }
      end
    end

    def db
      @db ||= PStore.new("db.pstore")
    end

    def db_id(base)
      "#{self.name}_#{base}"
    end

    def next_available_id
      all.sort_by(&:id).last.id + 1
    end
  end


  def save
    ensure_id
    self.class.db.transaction do |db|
      db[db_id] = self
    end
  end


  def db_id
    self.class.db_id(id)
  end


  def ensure_id
    self.id ||= self.class.next_available_id
  end
end
{'fraction_non_alphanumeric': 0.11338697878566203, 'fraction_numerical': 0.000731528895391368, 'mean_word_length': 1.8322981366459627, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1632105', 'n_tokens_mistral': 520, 'n_tokens_neox': 504, 'n_words': 118}