Skip to content
This repository
Browse code

use a boolean to designate "latest" versions

  • Loading branch information...
commit f854d0e606ee70f8f3d93389f1a64d877983ab2a 1 parent 3b49153
David Dollar ddollar authored
10 app/models/rubygem.rb
@@ -119,10 +119,16 @@ def update_attributes_from_gem_specification!(version, spec)
119 119 def reorder_versions
120 120 numbers = self.reload.versions.sort.reverse.map(&:number).uniq
121 121
122   - self.versions.each do |version|
123   - Version.without_callbacks(:reorder_versions) do
  122 + Version.without_callbacks(:reorder_versions) do
  123 + self.versions.each do |version|
124 124 version.update_attribute(:position, numbers.index(version.number))
125 125 end
  126 +
  127 + self.versions.update_all(:latest => false)
  128 +
  129 + versions.release.platforms.each do |platform|
  130 + versions.release.find_by_platform(platform).update_attributes(:latest => true)
  131 + end
126 132 end
127 133 end
128 134
8 app/models/version.rb
@@ -18,7 +18,7 @@ class Version < ActiveRecord::Base
18 18 }
19 19
20 20 named_scope :with_associated, { :conditions => ["rubygems.versions_count > 1"], :include => :rubygem, :order => "versions.built_at desc" }
21   - named_scope :latest, { :conditions => { :position => 0 }, :include => :rubygem }
  21 + named_scope :latest, { :conditions => { :latest => true }}
22 22 named_scope :prerelease, { :conditions => { :prerelease => true }}
23 23 named_scope :release, { :conditions => { :prerelease => false }}
24 24
@@ -32,7 +32,7 @@ def validate
32 32 end
33 33
34 34 def self.with_indexed
35   - all(:conditions => {:indexed => true}, :include => :rubygem, :order => "rubygems.name asc, number asc, built_at asc")
  35 + all(:conditions => {:indexed => true}, :include => :rubygem, :order => "rubygems.name asc, position asc")
36 36 end
37 37
38 38 def self.updated(limit=5)
@@ -50,6 +50,10 @@ def self.find_from_slug!(rubygem_id, slug)
50 50 find_by_rubygem_id_and_number_and_platform!(rubygem_id, number, platform)
51 51 end
52 52
  53 + def self.platforms
  54 + find(:all, :select => 'DISTINCT platform').map(&:platform)
  55 + end
  56 +
53 57 def to_s
54 58 number
55 59 end
11 db/migrate/20091021203534_add_latest_to_version.rb
... ... @@ -0,0 +1,11 @@
  1 +class AddLatestToVersion < ActiveRecord::Migration
  2 + def self.up
  3 + add_column :versions, :latest, :boolean
  4 +
  5 + Rubygem.all.each &:reorder_versions
  6 + end
  7 +
  8 + def self.down
  9 + remove_column :versions, :latest
  10 + end
  11 +end
3  db/schema.rb
@@ -9,7 +9,7 @@
9 9 #
10 10 # It's strongly recommended to check this file into your version control system.
11 11
12   -ActiveRecord::Schema.define(:version => 20091009213456) do
  12 +ActiveRecord::Schema.define(:version => 20091021203534) do
13 13
14 14 create_table "delayed_jobs", :force => true do |t|
15 15 t.integer "priority", :default => 0
@@ -134,6 +134,7 @@
134 134 t.boolean "prerelease"
135 135 t.integer "position"
136 136 t.integer "downloads_count", :default => 0
  137 + t.boolean "latest"
137 138 end
138 139
139 140 add_index "versions", ["built_at"], :name => "index_versions_on_built_at"
4 lib/gemcutter.rb
@@ -94,11 +94,11 @@ def specs_index
94 94 end
95 95
96 96 def latest_index
97   - Version.latest.release.map(&:to_index)
  97 + Version.latest.with_indexed.map(&:to_index)
98 98 end
99 99
100 100 def prerelease_index
101   - Version.prerelease.map(&:to_index)
  101 + Version.prerelease.with_indexed.map(&:to_index)
102 102 end
103 103
104 104 def perform

0 comments on commit f854d0e

Please sign in to comment.
Something went wrong with that request. Please try again.