Skip to content

Commit

Permalink
Removing the old hostess and pulling out the gemspec separately
Browse files Browse the repository at this point in the history
  • Loading branch information
qrush committed May 30, 2009
1 parent 60d555f commit b64c328
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 81 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -8,3 +8,4 @@ cache/
log/*
tmp/*
db/*.sqlite3
config/database.yml
52 changes: 4 additions & 48 deletions Rakefile
Expand Up @@ -31,7 +31,6 @@ task :bootstrap do
end
namespace :index do
desc "Create the index"
task :create do
require 'app/cutter'
Expand All @@ -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'
Expand Down Expand Up @@ -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
Expand Down
32 changes: 19 additions & 13 deletions app/models/rubygem.rb
Expand Up @@ -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)
Expand Down
8 changes: 0 additions & 8 deletions apps/hostess/config.ru

This file was deleted.

1 change: 0 additions & 1 deletion apps/hostess/views/index.haml

This file was deleted.

3 changes: 2 additions & 1 deletion test/factories/rubygem.rb
@@ -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
2 changes: 1 addition & 1 deletion test/test_helper.rb
Expand Up @@ -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

Expand Down
24 changes: 15 additions & 9 deletions test/unit/rubygem_test.rb
@@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down

0 comments on commit b64c328

Please sign in to comment.