Permalink
Browse files

Removing the old hostess and pulling out the gemspec separately

  • Loading branch information...
1 parent 60d555f commit b64c328a48b473518853ebe7240ae8ee6a12474c @qrush qrush committed May 30, 2009
Showing with 42 additions and 81 deletions.
  1. +1 −0 .gitignore
  2. +4 −48 Rakefile
  3. +19 −13 app/models/rubygem.rb
  4. +0 −8 apps/hostess/config.ru
  5. +0 −1 apps/hostess/views/index.haml
  6. +2 −1 test/factories/rubygem.rb
  7. +1 −1 test/test_helper.rb
  8. +15 −9 test/unit/rubygem_test.rb
View
@@ -8,3 +8,4 @@ cache/
log/*
tmp/*
db/*.sqlite3
+config/database.yml
View
@@ -31,7 +31,6 @@ task :bootstrap do
end
namespace :index do
-
desc "Create the index"
task :create do
require 'app/cutter'
@@ -45,49 +44,9 @@ namespace :index do
require 'app/indexer'
Gem::Cutter.indexer.update_index
end
-
- desc "Benchmark gemcutter's indexer vs rubygems"
- task :bench do
- require 'benchmark'
- # Clean directory
- # Copy 100 gems in
- # Generate gem index
- # Copy 100 more gems in
- # Run update
-
- commands = <<EOF
-git clean -dfxq server
-cp -r bench/old/*.gem server/cache
-gem generate_index -d server > /dev/null
-cp -r bench/new/*.gem server/cache
-EOF
- commands = commands.split("\n").join(";")
-
- code = <<EOF
-Gem.configuration.verbose = false
-i = Gem::Indexer.new('server', :build_legacy => false)
-def i.say(message) end
-i.update_index
-EOF
- code = code.split("\n").join(";")
- rb = "require 'rubygems/indexer';" + code
- gc = "require './lib/rubygems/indexer';" + code
-
- Benchmark.bm(9) do |b|
- b.report("rubygems ") do
- system(commands)
- system(%{ruby -rubygems -e "#{rb}"})
- end
- b.report("gemcutter") do
- system(commands)
- system(%{ruby -rubygems -e "#{gc}"})
- end
- end
- end
end
namespace :import do
-
desc 'Download all of the gems in rubygems.txt'
task :download do
require 'curb'
@@ -135,15 +94,12 @@ namespace :import do
end
desc 'Bring the gems through the gemcutter process'
- task :process do
- require 'rubygems/indexer'
- require 'app/app'
-
+ task :process => :environment do
gems = Dir[File.join(ARGV[1], "*.gem")]
puts "Processing #{gems.size} gems..."
- gems.each do |gem|
- puts gem
- Gem::Cutter.new(File.open(gem)).process
+ gems.each do |g|
+ puts g
+ Rubygem.create(:data => File.open(g))
end
end
end
View
@@ -4,27 +4,33 @@ class Rubygem < ActiveRecord::Base
has_many :dependencies
validates_presence_of :name
+ validates_uniqueness_of :name
- attr_accessor :data, :spec
- before_validation :parse_spec
- after_save :update_index
+ attr_accessor :spec, :path
+ before_validation :build
+ after_save :store
+
+ def self.pull_spec(data)
+ Gem::Format.from_file_by_path(data.path).spec
+ end
protected
- def parse_spec
- self.spec = Gem::Format.from_file_by_path(self.data.path).spec
- self.name = spec.name
+ def build
+ return unless self.spec
- cache = Gemcutter.server_path('gems', "#{spec.original_name}.gem")
- FileUtils.cp self.data.path, cache
- File.chmod 0644, cache
+ self.name = self.spec.name if self.name.blank?
version = self.versions.build(
- :authors => spec.authors,
- :description => spec.description || spec.summary,
- :number => spec.version)
+ :authors => self.spec.authors,
+ :description => self.spec.description || self.spec.summary,
+ :number => self.spec.version)
end
- def update_index
+ def store
+ cache = Gemcutter.server_path('gems', "#{self.spec.original_name}.gem")
+ FileUtils.cp self.path, cache
+ File.chmod 0644, cache
+
source_path = Gemcutter.server_path("source_index")
if File.exists?(source_path)
View
@@ -1,8 +0,0 @@
-$:.unshift File.expand_path(File.join(File.dirname(__FILE__)))
-
-require 'rubygems'
-require 'sinatra'
-require 'hostess'
-
-set :environment, :production
-run Gem::Hostess
@@ -1 +0,0 @@
-%h1 gems.gemcutter.org
@@ -1,6 +1,7 @@
Factory.define :rubygem do |rubygem|
rubygem.name { 'RGem' }
rubygem.token { 'asdf' }
- rubygem.data { gem_file("test-0.0.0.gem") }
rubygem.association :user
+ rubygem.spec { gem_spec }
+ rubygem.path { gem_file.path }
end
View
@@ -17,7 +17,7 @@ class Test::Unit::TestCase
include RR::Adapters::TestUnit unless include?(RR::Adapters::TestUnit)
end
-def gem_file(name)
+def gem_file(name = "test-0.0.0.gem")
ActionController::TestUploadedFile.new(File.join(File.dirname(__FILE__), 'gems', name), 'application/octet-stream', :binary)
end
View
@@ -1,16 +1,21 @@
require File.dirname(__FILE__) + '/../test_helper'
class RubygemTest < ActiveSupport::TestCase
- should_belong_to :user
- should_have_many :versions
- should_have_many :dependencies
+ context "with a rubygem" do
+ setup do
+ @rubygem = Factory(:rubygem)
+ end
- should "be valid with factory" do
- assert_valid Factory.build(:rubygem)
+ should_belong_to :user
+ should_have_many :versions
+ should_have_many :dependencies
+ should_validate_uniqueness_of :name
end
- should "respond to data" do
- assert Rubygem.new.respond_to?(:data)
+ should "pull spec out of the given gem" do
+ spec = Rubygem.pull_spec(gem_file)
+ assert_not_nil spec
+ assert spec.is_a?(Gem::Specification)
end
should "respond to spec" do
@@ -25,7 +30,7 @@ class RubygemTest < ActiveSupport::TestCase
stub(Gem::Format).from_file_by_path(anything).stub!.spec { @spec }
regenerate_index
- @rubygem = Rubygem.create(:data => @gem_file)
+ @rubygem = Rubygem.create(:spec => @spec, :path => @gem_file.path)
end
context "updating a gem" do
@@ -35,7 +40,8 @@ class RubygemTest < ActiveSupport::TestCase
@new_spec = gem_spec(:version => "1.0.0")
stub(Gem::Format).from_file_by_path(anything).stub!.spec { @new_spec }
- @rubygem.data = @new_gem_file
+ @rubygem.path = @new_gem_file.path
+ @rubygem.spec = @new_spec
@rubygem.save
end

0 comments on commit b64c328

Please sign in to comment.