<commit_before>module Media
  extend ActiveSupport::Concern

  included do
    extend FriendlyId
    include Titleable
    include Rateable

    # HACK: we need to return a relation but want to handle historical slugs
    scope :by_slug, -> (slug) {
      record = where(slug: slug)
      record = where(id: friendly.find(slug).id) if record.empty?
      record
    }

    friendly_id :slug_candidates, use: %i[slugged finders history]
    resourcify
    has_attached_file :cover_image
    has_attached_file :poster_image
    update_index("media##{name.tableize}") { self }

    has_and_belongs_to_many :genres
    has_many :castings, as: 'media'
    has_many :installments, as: 'media'
    has_many :franchises, through: :installments
    has_many :library_entries, as: 'media', dependent: :destroy
    has_many :mappings, as: 'media', dependent: :destroy
    delegate :year, to: :start_date, allow_nil: true

    validates_attachment :cover_image, content_type: {
      content_type: %w[image/jpg image/jpeg image/png]
    }
    validates_attachment :poster_image, content_type: {
      content_type: %w[image/jpg image/jpeg image/png]
    }
  end

  def slug_candidates<commit_msg>server: Media should determine index w/ #underscore, not #tableize<commit_after>module Media
  extend ActiveSupport::Concern

  included do
    extend FriendlyId
    include Titleable
    include Rateable

    # HACK: we need to return a relation but want to handle historical slugs
    scope :by_slug, -> (slug) {
      record = where(slug: slug)
      record = where(id: friendly.find(slug).id) if record.empty?
      record
    }

    friendly_id :slug_candidates, use: %i[slugged finders history]
    resourcify
    has_attached_file :cover_image
    has_attached_file :poster_image
    update_index("media##{name.underscore}") { self }

    has_and_belongs_to_many :genres
    has_many :castings, as: 'media'
    has_many :installments, as: 'media'
    has_many :franchises, through: :installments
    has_many :library_entries, as: 'media', dependent: :destroy
    has_many :mappings, as: 'media', dependent: :destroy
    delegate :year, to: :start_date, allow_nil: true

    validates_attachment :cover_image, content_type: {
      content_type: %w[image/jpg image/jpeg image/png]
    }
    validates_attachment :poster_image, content_type: {
      content_type: %w[image/jpg image/jpeg image/png]
    }
  end

  def slug_candidates
{'fraction_non_alphanumeric': 0.09203466776723071, 'fraction_numerical': 0.0, 'mean_word_length': 3.697674418604651, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6701348', 'n_tokens_mistral': 798, 'n_tokens_neox': 783, 'n_words': 205}