<commit_before>class License < ActiveRecord::Base
  has_many :artifacts

  def self.license_types
    License.all.pluck(:license_type).uniq
  end

  # TODO: Maybe move this whole code to attributes in the database?
  def self.type_image type, small=false
    name = type

    # All gpls use the same image
    if name.match(/gpl/)
      name = 'gpl'
    end

    img = "licenses/#{name}#{small ? '-small' : ''}"
    extension = 'svg'

    # find the correct image extension
    ['svg', 'png', 'jpg'].each do |ext|
      extension = ext if Rails.application.assets.find_asset("#{img}.#{ext}")
    end

    # Return full image path
    "#{img}.#{extension}"
  end

  def self.type_name type
    type
  end

  def image_url small=false
    License.type_image(short_name, small)
  end

  # Override find to use the shortname and then try the ID
  def self.find(id)
    where(short_name: id).first || super
  end
end
<commit_msg>Fix for sprockets deprecated method 'find_assets'<commit_after>class License < ActiveRecord::Base
  has_many :artifacts

  def self.license_types
    License.all.pluck(:license_type).uniq
  end

  # TODO: Maybe move this whole code to attributes in the database?
  def self.type_image type, small=false
    name = type

    # All gpls use the same image
    if name.match(/gpl/)
      name = 'gpl'
    end

    img = "licenses/#{name}#{small ? '-small' : ''}"
    extension = 'svg'

    # find the correct image extension
    ['svg', 'png', 'jpg'].each do |ext|
      extension = ext if license_image_present?("#{img}.#{ext}")
    end

    # Return full image path
    "#{img}.#{extension}"
  end

  def self.type_name type
    type
  end

  def image_url small=false
    License.type_image(short_name, small)
  end

  # Override find to use the shortname and then try the ID
  def self.find(id)
    where(short_name: id).first || super
  end

  private
  def self.license_image_present? filename
    if Rails.env.production?
      Rails.application.assets_manifest.assets[filename]
    else
      File.exists?(File.join(Rails.root, 'app/assets/images/', filename))
    end
  end

end

{'fraction_non_alphanumeric': 0.11142721669037459, 'fraction_numerical': 0.0, 'mean_word_length': 2.996212121212121, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3585265', 'n_tokens_mistral': 694, 'n_tokens_neox': 681, 'n_words': 202}