Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

support prerelease gems

  • Loading branch information...
commit 8e26bfe60493f809a296db078debe392af39991d 1 parent d2dbf5e
@ddollar ddollar authored
View
2  app/controllers/home_controller.rb
@@ -4,6 +4,6 @@ def index
@latest = Rubygem.latest
@downloaded = Rubygem.downloaded
- @updated = Version.published
+ @updated = Version.release.published
end
end
View
5 app/metal/hostess.rb
@@ -28,6 +28,11 @@ def serve(path, redirect = false)
serve(current_path)
end
+ get "/prerelease_specs.#{Gem.marshal_version}.gz" do
+ content_type('application/x-gzip')
+ serve(current_path)
+ end
+
get "/quick/Marshal.#{Gem.marshal_version}/*.gemspec.rz" do
content_type('application/x-deflate')
serve(current_path)
View
26 app/models/version.rb
@@ -15,6 +15,11 @@ class Version < ActiveRecord::Base
{ :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.")
@@ -37,6 +42,15 @@ 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
@@ -52,7 +66,17 @@ def update_attributes_from_gem_specification!(spec)
end
def to_index
- [rubygem.name, Gem::Version.new(number), platform]
+ [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)
View
10 db/migrate/20090917035818_add_prerelease_to_versions.rb
@@ -0,0 +1,10 @@
+class AddPrereleaseToVersions < ActiveRecord::Migration
+ def self.up
+ add_column :versions, :prerelease, :boolean
+ Version.update_all(:prerelease => false)
+ end
+
+ def self.down
+ remove_column :versions, :prerelease
+ end
+end
View
3  db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20090910143608) do
+ActiveRecord::Schema.define(:version => 20090917035818) do
create_table "delayed_jobs", :force => true do |t|
t.integer "priority", :default => 0
@@ -113,6 +113,7 @@
t.string "platform"
t.datetime "created_at"
t.boolean "indexed", :default => true
+ t.boolean "prerelease"
end
add_index "versions", ["rubygem_id"], :name => "index_versions_on_rubygem_id"
View
7 lib/vault.rb
@@ -12,13 +12,17 @@ def specs_index
end
def latest_index
- Version.with_indexed.inject({}) { |memo, version|
+ Version.release.with_indexed.inject({}) { |memo, version|
key = "#{version.rubygem_id}-#{version.platform}"
memo[key] = version if memo[key].blank? || (version <=> memo[key]) == 1
memo
}.values.map(&:to_index)
end
+ def prerelease_index
+ Version.prerelease.map(&:to_index)
+ end
+
def write_gem
cache_path = "gems/#{spec.original_name}.gem"
VaultObject.store(cache_path, self.raw_data, OPTIONS)
@@ -32,6 +36,7 @@ def write_gem
def update_index
upload("specs.#{Gem.marshal_version}.gz", specs_index)
upload("latest_specs.#{Gem.marshal_version}.gz", latest_index)
+ upload("prerelease_specs.#{Gem.marshal_version}.gz", prerelease_index)
end
def upload(key, value)
View
8 test/unit/hostess_test.rb
@@ -15,6 +15,14 @@ def remove(path)
FileUtils.rm(path) if File.exists?(path)
end
+ should "return prerelease specs" do
+ file = "/prerelease_specs.4.8.gz"
+ touch file
+ get file
+ assert_not_nil last_response.headers["Cache-Control"]
+ assert_equal 200, last_response.status
+ end
+
should "return latest specs" do
file = "/latest_specs.4.8.gz"
touch file
View
17 test/unit/version_test.rb
@@ -94,6 +94,23 @@ class VersionTest < ActiveSupport::TestCase
end
end
+ context "with mixed release and prerelease versions" do
+ setup do
+ @prerelease = Factory(:version, :number => '1.0.rc1')
+ @release = Factory(:version, :number => '1.0')
+ end
+
+ should "know if it is a prelease version" do
+ assert @prerelease.prerelease?
+ assert !@release.prerelease?
+ end
+
+ should "return prerelease gems from the prerelease named scope" do
+ assert_equal [@prerelease], Version.prerelease
+ assert_equal [@release], Version.release
+ end
+ end
+
context "with a few versions" do
setup do
@thin = Factory(:version, :authors => "thin", :created_at => 1.year.ago)
Please sign in to comment.
Something went wrong with that request. Please try again.