<commit_before>class Version < ActiveRecord::Base
  include Pacecar

  belongs_to :rubygem, :counter_cache => true
  has_many :dependencies, :dependent => :destroy

  validates_format_of :number, :with => /^#{Gem::Version::VERSION_PATTERN}$/

  named_scope :owned_by, lambda { |user|
    { :conditions => { :rubygem_id => user.rubygem_ids } }
  }

  named_scope :subscribed_to_by, lambda { |user|
    { :conditions => { :rubygem_id => user.subscribed_gem_ids } }
  }

  named_scope :prerelease, { :conditions => { :prerelease => true  }}
  named_scope :release,    { :conditions => { :prerelease => false }}

  before_save :update_prerelease

  def validate
    if new_record? && Version.exists?(:rubygem_id => rubygem_id, :number => number, :platform => platform)
      errors.add_to_base("A version already exists with this number or platform.")
    end
  end

  def self.with_indexed
    all(:conditions => {:indexed => true}, :include => :rubygem, :order => "rubygems.name asc, number asc, built_at asc")
  end

  def self.published(limit=5)
    created_at_before(DateTime.now.utc).by_created_at(:desc).limited(limit)
  end

  def to_s
    number
  end

  def to_title
    "#{rubygem.name} (#{to_s})"
  end

  def update_prerelease
    self[:prerelease] = to_gem_version.prerelease?
    true
  end

  def to_gem_version
    Gem::Version.new(number)
  end

  def info
    [ description, summary, "This rubygem does not have a description or summary." ].detect(&:present?)
  end

  def update_attributes_from_gem_specification!(spec)
    self.update_attributes!(
      :authors           => spec.authors.join(', '),
      :description       => spec.description,
      :summary           => spec.summary,
      :rubyforge_project => spec.rubyforge_project,
      :built_at          => spec.date,
      :indexed           => false
    )
  end

  def to_index
    [rubygem.name, to_gem_version, platform]
  end

  def <=>(other)
    if self.built_at > other.built_at
      1
    elsif self.built_at < other.built_at
      -1
    else self.built_at == other.built_at
      self.created_at <=> other.created_at
    end
  end

  def <=>(other)
    if self.built_at > other.built_at
      1
    elsif self.built_at < other.built_at
      -1
    else self.built_at == other.built_at
      self.created_at <=> other.created_at
    end
  end

  def built_at_date
    built_at.to_date.to_formatted_s(:long)
  end

  def to_install
    command = "gem install #{rubygem.name}"
    command << " -v #{number}" if rubygem.versions.current != self
    command
  end
end<commit_msg>Just use Rubygems to compare versions<commit_after>class Version < ActiveRecord::Base
  include Pacecar

  belongs_to :rubygem, :counter_cache => true
  has_many :dependencies, :dependent => :destroy

  validates_format_of :number, :with => /^#{Gem::Version::VERSION_PATTERN}$/

  named_scope :owned_by, lambda { |user|
    { :conditions => { :rubygem_id => user.rubygem_ids } }
  }

  named_scope :subscribed_to_by, lambda { |user|
    { :conditions => { :rubygem_id => user.subscribed_gem_ids } }
  }

  named_scope :prerelease, { :conditions => { :prerelease => true  }}
  named_scope :release,    { :conditions => { :prerelease => false }}

  before_save :update_prerelease

  def validate
    if new_record? && Version.exists?(:rubygem_id => rubygem_id, :number => number, :platform => platform)
      errors.add_to_base("A version already exists with this number or platform.")
    end
  end

  def self.with_indexed
    all(:conditions => {:indexed => true}, :include => :rubygem, :order => "rubygems.name asc, number asc, built_at asc")
  end

  def self.published(limit=5)
    created_at_before(DateTime.now.utc).by_created_at(:desc).limited(limit)
  end

  def to_s
    number
  end

  def to_title
    "#{rubygem.name} (#{to_s})"
  end

  def update_prerelease
    self[:prerelease] = to_gem_version.prerelease?
    true
  end

  def to_gem_version
    Gem::Version.new(number)
  end

  def info
    [ description, summary, "This rubygem does not have a description or summary." ].detect(&:present?)
  end

  def update_attributes_from_gem_specification!(spec)
    self.update_attributes!(
      :authors           => spec.authors.join(', '),
      :description       => spec.description,
      :summary           => spec.summary,
      :rubyforge_project => spec.rubyforge_project,
      :built_at          => spec.date,
      :indexed           => false
    )
  end

  def to_index
    [rubygem.name, to_gem_version, platform]
  end

  def <=>(other)
    self.to_gem_version <=> other.to_gem_version
  end

  def built_at_date
    built_at.to_date.to_formatted_s(:long)
  end

  def to_install
    command = "gem install #{rubygem.name}"
    command << " -v #{number}" if rubygem.versions.current != self
    command
  end
end
{'fraction_non_alphanumeric': 0.11945889698231009, 'fraction_numerical': 0.0012486992715920915, 'mean_word_length': 3.161038961038961, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 59, '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': '1836830', 'n_tokens_mistral': 1659, 'n_tokens_neox': 1595, 'n_words': 359}