<commit_before>class Post < ActiveRecord::Base

  validates_presence_of :slug, unless: -> { micro? }

  has_many :categorized_posts, dependent: :destroy

  enum status: [ :publish, :pending, :draft, :invisible ]
  enum kind: [ :post, :page, :micro ]

end<commit_msg>add hooks for slugs and titles depending on type<commit_after>class Post < ActiveRecord::Base

  validates_presence_of :slug, unless: -> { micro? }

  has_many :categorized_posts, dependent: :destroy

  enum status: [ :publish, :pending, :draft, :invisible ]
  enum kind: [ :post, :page, :micro ]

  before_validation :slugify, unless: :micro?
  before_validation :strip_title, if: :micro?

  protected

  def strip_title
    self.title = nil
  end

  def slugify
    if slug.to_s.empty?
      self.slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
    end
  end

end
{'fraction_non_alphanumeric': 0.13372781065088757, 'fraction_numerical': 0.0, 'mean_word_length': 3.9473684210526314, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2439029', 'n_tokens_mistral': 299, 'n_tokens_neox': 288, 'n_words': 76}