Permalink
Browse files

stashing work on quick

  • Loading branch information...
1 parent 572a68e commit 73308b5b6a169b37381e469ab4c434c09de257a8 @jnewland committed Feb 9, 2009
Showing with 149 additions and 20 deletions.
  1. +0 −1 config.ru
  2. +59 −1 lib/rack_rubygems.rb
  3. +42 −10 spec/rack_rubygems_spec.rb
  4. +48 −8 spec/spec_helper.rb
View
@@ -3,5 +3,4 @@ $:.unshift LIB_PATH
require 'rack_rubygems'
use Rack::Lint
use GemsAndRdocs, :urls => ['/cache', '/doc'], :root => Gem.dir
-use Rack::Compress
run RackRubygems.new
View
@@ -4,12 +4,13 @@
require 'zlib'
require 'erb'
require 'rubygems'
-require 'rubygems/doc_manager'
require File.expand_path(File.dirname(__FILE__) + "/rack_compress")
require File.expand_path(File.dirname(__FILE__) + "/gems_and_rdocs")
class RackRubygems < Sinatra::Base
+ use Rack::Compress
+
head "/Marshal.#{Gem.marshal_version}" do
content_type 'application/octet-stream'
response['Content-Length'] = source_index.length.to_s
@@ -47,6 +48,36 @@ class RackRubygems < Sinatra::Base
yaml
end
+ get '/quick/index' do
+ content_type 'text/plain'
+ source_index.map { |name,| name }.sort.join("\n")
+ end
+
+ get '/quick/index.rz' do
+ content_type 'application/x-deflate'
+ Gem.deflate(source_index.map { |name,| name }.sort.join("\n"))
+ end
+
+ get "/quick/latest_index" do
+ content_type 'text/plain'
+ source_index.latest_specs.map { |spec| spec.full_name }.sort.join("\n")
+ end
+
+ get "/quick/latest_index.rz" do
+ content_type 'application/x-deflate'
+ Gem.deflate(source_index.latest_specs.map { |spec| spec.full_name }.sort.join("\n"))
+ end
+
+ get "/quick/:selector.gemspec.rz" do
+ content_type 'application/x-deflate'
+ Gem.deflate(quick(params[:selector]).to_yaml)
+ end
+
+ get "/quick/Marshal.#{Gem.marshal_version}/:selector.gemspec.rz" do
+ content_type 'application/x-deflate'
+ Gem.deflate(marshal(quick(params[:selector])))
+ end
+
def source_index
@gem_dir = Gem.dir
@spec_dir = File.join @gem_dir, 'specifications'
@@ -56,6 +87,33 @@ def source_index
@source_index
end
+ def quick(selector)
+ source_index
+ return unless selector =~ /(.*?)-([0-9.]+)(-.*?)?/
+ name, version, platform = $1, $2, $3
+ specs = source_index.search Gem::Dependency.new(name, version)
+
+ selector = [name, version, platform].map { |s| s.inspect }.join ' '
+
+ if platform
+ platform = Gem::Platform.new platform.sub(/^-/, '')
+ else
+ platform = Gem::Platform::RUBY
+ end
+
+ specs = specs.select { |s| s.platform == platform }
+
+ if specs.empty?
+ content_type 'text/plain'
+ not_found "No gems found matching #{selector}"
+ elsif specs.length > 1
+ content_type 'text/plain'
+ error 500, "Multiple gems found matching #{selector}"
+ else
+ specs.first
+ end
+ end
+
def marshal(data)
content_type 'application/octet-stream'
Marshal.dump(data)
View
@@ -55,16 +55,48 @@
end
describe "provides access to individual gemspecs" do
- it "via name and version"
- it "via name, version, and platform"
- it "performing substring matching"
- it "and a quick index"
- it "and a quick compressed index"
- it "and a latest index"
- it "and a compressed latest index"
- it "returns a 404 when accessing a missing gem"
- it "marshalled via name and version"
- it "marshalled via name, version, and platform"
+ it "via name and version" do
+ should_match_webrick_behavior "/quick/a-1.gemspec.rz", :quick
+ end
+
+ it "via name, version, and platform" do
+ a1_p = quick_gem 'a', '1' do |s| s.platform = Gem::Platform.local end
+ should_match_webrick_behavior "/quick/a-1-#{Gem::Platform.local}.gemspec.rz", :quick
+ end
+
+ it "performing substring matching" do
+ ab1 = quick_gem 'ab', '1'
+ should_match_webrick_behavior "/quick/ab-1.gemspec.rz", :quick
+ end
+
+ it "via a quick index" do
+ should_match_webrick_behavior "/quick/index", :quick
+ end
+
+ it "via a quick compressed index" do
+ should_match_webrick_behavior "/quick/index.rz", :quick
+ end
+
+ it "via a quick latest index" do
+ should_match_webrick_behavior "/quick/latest_index", :quick
+ end
+
+ it "via a quick compressed latest index" do
+ should_match_webrick_behavior "/quick/latest_index.rz", :quick
+ end
+
+ it "returns a 404 when accessing a missing gem" do
+ get "/quick/z-9.gemspec.rz"
+ @response.should_not be_ok
+ end
+
+ it "marshalled via name and version" do
+ should_match_webrick_behavior "/quick/Marshal.#{Gem.marshal_version}/a-1.gemspec.rz", :quick
+ end
+
+ it "marshalled via name, version, and platform" do
+ should_match_webrick_behavior "/quick/Marshal.#{Gem.marshal_version}/a-1-#{Gem::Platform.local}.gemspec.rz", :quick
+ end
end
end
View
@@ -6,12 +6,15 @@
require 'spec/interop/test'
require 'stringio'
require 'webrick'
-
+require 'rubygems/test_utilities'
+require 'tmpdir'
+require 'uri'
+
Sinatra::Default.set(
:environment => :test,
:run => false,
:raise_errors => true,
- :logging => false
+ :logging => true
)
require File.expand_path(File.dirname(__FILE__) + "/../lib/rack_rubygems.rb")
@@ -40,6 +43,7 @@ def should_match_webrick_behavior(url, server_method, method = :get)
}
end
+ #stub gem
def quick_gem(gemname, version='2')
require 'rubygems/specification'
@@ -70,11 +74,6 @@ def quick_gem(gemname, version='2')
end
def write_file(path)
- tmpdir = nil
- Dir.chdir Dir.tmpdir do tmpdir = Dir.pwd end # HACK OSX /private/tmp
- @tempdir = File.join tmpdir, "test_rubygems_#{$$}"
- @tempdir.untaint
- @gemhome = File.join @tempdir, "gemhome"
path = File.join(@gemhome, path)
dir = File.dirname path
FileUtils.mkdir_p dir
@@ -94,11 +93,52 @@ def process_based_port
Spec::Runner.configure do |config|
config.before(:each) {
+
+ tmpdir = nil
+ Dir.chdir Dir.tmpdir do tmpdir = Dir.pwd end # HACK OSX /private/tmp
+ @tempdir = File.join tmpdir, "test_rubygems_#{$$}"
+ @tempdir.untaint
+ @gemhome = File.join @tempdir, "gemhome"
+ @gemcache = File.join(@gemhome, "source_cache")
+ @usrcache = File.join(@gemhome, ".gem", "user_cache")
+ @latest_usrcache = File.join(@gemhome, ".gem", "latest_user_cache")
+ @userhome = File.join @tempdir, 'userhome'
+
+ @orig_ENV_HOME = ENV['HOME']
+ ENV['HOME'] = @userhome
+ Gem.instance_variable_set :@user_home, nil
+
+ FileUtils.mkdir_p @gemhome
+ FileUtils.mkdir_p @userhome
+
+ ENV['GEMCACHE'] = @usrcache
+ Gem.use_paths(@gemhome)
+ Gem.loaded_specs.clear
+
+ Gem.configuration.verbose = true
+ Gem.configuration.update_sources = true
+
+ @gem_repo = "http://gems.example.com/"
+ @uri = URI.parse @gem_repo
+ Gem.sources.replace [@gem_repo]
+
+ Gem::SpecFetcher.fetcher = nil
+
+ @orig_BASERUBY = Gem::ConfigMap[:BASERUBY]
+ Gem::ConfigMap[:BASERUBY] = Gem::ConfigMap[:RUBY_INSTALL_NAME]
+
+ @orig_arch = Gem::ConfigMap[:arch]
+
+ @marshal_version = "#{Marshal::MAJOR_VERSION}.#{Marshal::MINOR_VERSION}"
+
+ @private_key = File.expand_path File.join(File.dirname(__FILE__), 'private_key.pem')
+ @public_cert = File.expand_path File.join(File.dirname(__FILE__), 'public_cert.pem')
+
@app = Rack::Builder.new {
use GemsAndRdocs, :urls => ['/cache', '/doc'], :root => Gem.dir
- use Rack::Compress
run RackRubygems.new
}
+
@a1 = quick_gem 'a', '1'
@a2 = quick_gem 'a', '2'

0 comments on commit 73308b5

Please sign in to comment.