<commit_before>class Rubygem < ActiveRecord::Base

  has_many :owners, :through => :ownerships, :source => :user
  has_many :ownerships, :dependent => :destroy
  has_many :subscribers, :through => :subscriptions, :source => :user
  has_many :subscriptions, :dependent => :destroy
  has_many :versions, :dependent => :destroy
  has_many :web_hooks, :dependent => :destroy
  has_one :linkset, :dependent => :destroy

  validate :ensure_name_format
  validates_presence_of :name
  validates_uniqueness_of :name

  scope :with_versions,
    :conditions => "rubygems.id IN (SELECT rubygem_id FROM versions where versions.indexed IS true)"

  scope :with_one_version,
    :select => 'rubygems.*',
    :joins  => :versions,
    :group  => column_names.map{ |name| "rubygems.#{name}" }.join(', '),
    :having => 'COUNT(versions.id) = 1'

  scope :name_is, lambda { |name| {
    :conditions => ["name = ?", name.strip],
    :limit      => 1 }
  }

  scope :search, lambda { |query| {
    :conditions => ["versions.indexed and (upper(name) like upper(:query) or upper(versions.description) like upper(:query))",
      {:query => "%#{query.strip}%"}],
    :include    => :versions,
    :order      => "rubygems.downloads desc" }
  }

  scope :name_starts_with, lambda { |letter| {
    :conditions => ["upper(name) like upper(?)", "#{letter}%" ] }
  }

  def ensure_name_format
    if name.class != String
      errors.add :name, "must be a String"
    elsif name =~ /^[\d]+$/
      errors.add :name, "must include at least one letter"
    elsif name =~ /[^\d\w\-\.]/
      errors.add :name, "can only include letters, numbers, dashes, and underscores"
    end
  end

  def all_errors(version = nil)
    [self, linkset, version].compact.map do |ar|
      ar.errors.full_messages
    end.flatten.join(", ")
  end

  def self.total_count
    with_versions.count
  end

  def self.latest(limit=5)
    with_one_version.order("created_at desc").limit(limit)
  end<commit_msg>Change AR 3.0 query syntax for Rubygem<commit_after>class Rubygem < ActiveRecord::Base

  has_many :owners, :through => :ownerships, :source => :user
  has_many :ownerships, :dependent => :destroy
  has_many :subscribers, :through => :subscriptions, :source => :user
  has_many :subscriptions, :dependent => :destroy
  has_many :versions, :dependent => :destroy
  has_many :web_hooks, :dependent => :destroy
  has_one :linkset, :dependent => :destroy

  validate :ensure_name_format
  validates_presence_of :name
  validates_uniqueness_of :name

  scope :with_versions,
    where("rubygems.id IN (SELECT rubygem_id FROM versions where versions.indexed IS true)")

  scope :with_one_version,
    select('rubygems.*').
    joins(:versions).
    group(column_names.map{ |name| "rubygems.#{name}" }.join(', ')).
    having('COUNT(versions.id) = 1')

  scope :name_is, lambda { |name| 
    where(:name => name.strip).
    limit(1)
  }

  scope :search, lambda { |query| 
    where(["versions.indexed and (upper(name) like upper(:query) or upper(versions.description) like upper(:query))", {:query => "%#{query.strip}%"}]).
    includes(:versions).
    order("rubygems.downloads desc")
  }

  scope :name_starts_with, lambda { |letter| 
    where(["upper(name) like upper(?)", "#{letter}%" ])
  }

  def ensure_name_format
    if name.class != String
      errors.add :name, "must be a String"
    elsif name =~ /^[\d]+$/
      errors.add :name, "must include at least one letter"
    elsif name =~ /[^\d\w\-\.]/
      errors.add :name, "can only include letters, numbers, dashes, and underscores"
    end
  end

  def all_errors(version = nil)
    [self, linkset, version].compact.map do |ar|
      ar.errors.full_messages
    end.flatten.join(", ")
  end

  def self.total_count
    with_versions.count
  end

  def self.latest(limit=5)
    with_one_version.order("created_at desc").limit(limit)
  end
{'fraction_non_alphanumeric': 0.1504149377593361, 'fraction_numerical': 0.002074688796680498, 'mean_word_length': 3.6751515151515153, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4586284', 'n_tokens_mistral': 1324, 'n_tokens_neox': 1289, 'n_words': 322}