<commit_before>class Wor::Classifier < ActiveRecord::Base
  attr_accessible :name, :classifier_type, :slug

  self.table_name = :wor_classifiers

  has_many :classifier_posts
  has_many :posts, through: :classifier_posts, order: 'publication_date desc'

  scope :categories, conditions: {classifier_type: 'category'}
  scope :tags, conditions: {classifier_type: 'tag'}

  after_create :after_create


  def update_slug(_slug)
    slug_sanitize = Wor::Slugs.sanitize(_slug)
    _version = 0
    while Wor::Classifier.where("id<>? and slug=?", id, slug_sanitize).first
      _version += 1
      slug_sanitize    = "#{slug_sanitize}-#{_version}" 
    end

    self.update_attributes({slug: slug_sanitize})
  end


  private

  def after_create
    self.update_slug(name)
  end
end
<commit_msg>There can exist the same slug for different classifier types<commit_after>class Wor::Classifier < ActiveRecord::Base
  attr_accessible :name, :classifier_type, :slug

  self.table_name = :wor_classifiers

  has_many :classifier_posts
  has_many :posts, through: :classifier_posts, order: 'publication_date desc'

  scope :categories, conditions: { classifier_type: :category }
  scope :tags, conditions: { classifier_type: :tag }

  after_create :after_create

  def update_slug(_slug)
    slug_sanitize = Wor::Slugs.sanitize(_slug)
    _version = 0

    while Wor::Classifier.where("id<>? and slug=? and classifier_type=?", id, slug_sanitize, classifier_type).first
      _version += 1
      slug_sanitize = "#{slug_sanitize}-#{_version}"
    end

    update_attributes(slug: slug_sanitize)
  end

  private

  def after_create
    update_slug(name)
  end
end

{'fraction_non_alphanumeric': 0.10357359176256814, 'fraction_numerical': 0.0024227740763173833, 'mean_word_length': 4.581081081081081, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '5296527', 'n_tokens_mistral': 563, 'n_tokens_neox': 550, 'n_words': 124}