Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cleaned up a bunch of file names

  • Loading branch information...
commit 325ace5d364436dd0c4dab1d269ea4c7b8ed30d8 1 parent eedced0
Yehuda Katz + Carl Lerche authored
View
2  LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2009 YOUR NAME
+Copyright (c) 2009 Engine Yard
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
3  Rakefile
@@ -15,13 +15,12 @@ spec = Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.has_rdoc = true
s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
- s.summary = SUMMARY
+ s.summary = ""
# Uncomment this to add a dependency
# s.add_dependency "foo"
s.require_path = 'lib'
- s.autorequire = GEM
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
end
View
4 TODO
@@ -1,4 +0,0 @@
-TODO:
-Fix LICENSE with your name
-Fix Rakefile with your name and contact info
-Add your code to lib/<%= name %>.rb
View
39 lib/bundler.rb
@@ -1,36 +1,5 @@
-require "bundler/faster_source_index"
-require "bundler/fetcher"
+require "rubygems/remote_fetcher"
+require "bundler/finder"
+require "bundler/gem_specification"
-# require "rubygems"
-# require "rubygems/remote_fetcher"
-# require "pp"
-#
-# index = nil
-# File.open("dumped", "r") do |f|
-# index = Marshal.load(f.read)
-# end
-#
-# index = FasterSourceIndex.new(index)
-#
-# t = Time.now
-#
-# # ENV["GEM_RESOLVER_DEBUG"] = "true"
-#
-# list = {
-# "rails" => ">= 0"
-# # "merb-core" => ">= 0",
-# # "merb-haml" => ">= 0",
-# # "merb_datamapper" => ">= 0"
-# }.map {|k,v| Gem::Dependency.new(k, v)}
-#
-# require File.expand_path(File.join(File.dirname(__FILE__), "..", "gem_resolver", "lib", "gem_resolver"))
-# pp GemResolver.resolve(list, index).all_specs.map {|x| x.full_name }
-#
-# puts "TOTAL: #{Time.now - t}"
-#
-# # deflated = Gem::RemoteFetcher.fetcher.fetch_path("#{Gem.sources.first}/Marshal.4.8.Z"); nil
-# # inflated = Gem.inflate deflated; nil
-# # index = Marshal.load(inflated); nil
-# # File.open("dumped", "w") do |f|
-# # f.puts inflated
-# # end
View
19 lib/bundler/faster_source_index.rb
@@ -1,19 +0,0 @@
-class FasterSourceIndex
- def initialize(index)
- @index = index
- @new_index = Hash.new {|h,k| h[k] = {}}
- @index.gems.values.each do |spec|
- @new_index[spec.name][spec.version] = spec
- end
- @results = {}
- end
-
- def search(dependency)
- @results[dependency.hash] ||= begin
- possibilities = @new_index[dependency.name].values
- possibilities.select do |spec|
- dependency =~ spec
- end.sort_by {|s| s.version }
- end
- end
-end
View
14 lib/bundler/fetcher.rb
@@ -1,14 +0,0 @@
-require "rubygems/remote_fetcher"
-
-module Bundler
- class Fetcher
- def self.fetch(source)
- deflated = Gem::RemoteFetcher.fetcher.fetch_path("#{source}/Marshal.4.8.Z")
- inflated = Gem.inflate deflated
- index = Marshal.load(inflated)
- FasterSourceIndex.new(index)
- rescue Gem::RemoteFetcher::FetchError => e
- raise ArgumentError, "#{source} is not a valid source: #{e.message}"
- end
- end
-end
View
41 lib/bundler/finder.rb
@@ -0,0 +1,41 @@
+module Bundler
+ class Finder
+ def initialize(*sources)
+ @results = {}
+ @index = Hash.new { |h,k| h[k] = {} }
+
+ sources.each { |source| fetch(source) }
+ end
+
+ def resolve(*dependencies)
+ resolved = GemResolver.resolve(dependencies, self)
+ resolved && resolved.all_specs
+ end
+
+ def fetch(source)
+ deflated = Gem::RemoteFetcher.fetcher.fetch_path("#{source}/Marshal.4.8.Z")
+ inflated = Gem.inflate deflated
+
+ append(Marshal.load(inflated), source)
+ rescue Gem::RemoteFetcher::FetchError => e
+ raise ArgumentError, "#{source} is not a valid source: #{e.message}"
+ end
+
+ def append(index, source)
+ index.gems.values.each do |spec|
+ spec.source = source
+ @index[spec.name][spec.version] ||= spec
+ end
+ self
+ end
+
+ def search(dependency)
+ @results[dependency.hash] ||= begin
+ possibilities = @index[dependency.name].values
+ possibilities.select do |spec|
+ dependency =~ spec
+ end.sort_by {|s| s.version }
+ end
+ end
+ end
+end
View
10 lib/bundler/gem_specification.rb
@@ -0,0 +1,10 @@
+module Gem
+ class Specification
+ attribute :source
+
+ def source=(source)
+ @source = source.is_a?(URI) ? source : URI.parse(source)
+ raise ArgumentError, "The source must be an absolute URI" unless @source.absolute?
+ end
+ end
+end
View
42 spec/fetcher_spec.rb
@@ -1,14 +1,44 @@
require File.join(File.dirname(__FILE__), "spec_helper")
describe "Fetcher" do
- it "gets the remote index and returns a source index" do
- index = Bundler::Fetcher.fetch("file://#{File.expand_path(File.dirname(__FILE__))}/fixtures")
- index.should be_kind_of(FasterSourceIndex)
+ before(:each) do
+ @source = URI.parse("file://#{File.expand_path(File.dirname(__FILE__))}/fixtures")
+ @other = URI.parse("file://#{File.expand_path(File.dirname(__FILE__))}/fixtures2")
+ @finder = Bundler::Finder.new(@source, @other)
+ end
+
+ it "stashes the source in the returned gem specification" do
+ @finder.search(Gem::Dependency.new("abstract", ">= 0")).first.source.should == @source
+ end
+
+ it "uses the first source that was passed in if multiple sources have the same gem" do
+ @finder.search(build_dep("activerecord", "= 2.3.2")).first.source.should == @source
end
it "raises if the source is invalid" do
- lambda { Bundler::Fetcher.fetch("file://not/a/gem/source") }.should raise_error(ArgumentError)
- lambda { Bundler::Fetcher.fetch("http://localhost") }.should raise_error(ArgumentError)
- lambda { Bundler::Fetcher.fetch("http://google.com/not/a/gem/location") }.should raise_error(ArgumentError)
+ lambda { Bundler::Finder.new.fetch("file://not/a/gem/source") }.should raise_error(ArgumentError)
+ lambda { Bundler::Finder.new.fetch("http://localhost") }.should raise_error(ArgumentError)
+ lambda { Bundler::Finder.new.fetch("http://google.com/not/a/gem/location") }.should raise_error(ArgumentError)
+ end
+
+ it "accepts multiple source indexes" do
+ @finder.search(Gem::Dependency.new("abstract", ">= 0")).size.should == 1
+ @finder.search(Gem::Dependency.new("merb-core", ">= 0")).size.should == 2
+ end
+
+ it "resolves rails" do
+ specs = @finder.resolve(build_dep('rails', '>= 0'))
+ specs.should match_gems(
+ "rails" => ["2.3.2"],
+ "actionpack" => ["2.3.2"],
+ "actionmailer" => ["2.3.2"],
+ "activerecord" => ["2.3.2"],
+ "activeresource" => ["2.3.2"],
+ "activesupport" => ["2.3.2"],
+ "rake" => ["0.8.7"]
+ )
+
+ specs.select { |spec| spec.name == "activeresource" && spec.source == @other }.should have(1).item
+ specs.select { |spec| spec.name == "activerecord" && spec.source == @source }.should have(1).item
end
end
View
5 spec/faster_source_index_spec.rb → spec/finder_spec.rb
@@ -1,7 +1,6 @@
require File.join(File.dirname(__FILE__), "spec_helper")
-require "bundler/faster_source_index"
-describe "FasterSourceIndex" do
+describe "Finder" do
before(:all) do
index = build_index do
add_spec "activemerchant", "1.4.1" do
@@ -14,7 +13,7 @@
end
end
- @faster = FasterSourceIndex.new(index)
+ @faster = Bundler::Finder.new.append(index, "http://foo")
end
def only_have_specs(*names)
View
40 spec/gem_specification_spec.rb
@@ -0,0 +1,40 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+describe "Gem::Specification" do
+
+ it "is able to store the source URI of the gem as a URI" do
+ spec = Gem::Specification.new do |s|
+ s.name = 'greeter'
+ s.version = '1.0'
+ s.source = 'http://gems.rubyforge.org'
+ end
+
+ spec.source.should == URI.parse("http://gems.rubyforge.org")
+ end
+
+ it "does not consider two gem specs with different sources to be the same" do
+ spec1 = Gem::Specification.new do |s|
+ s.name = 'greeter'
+ s.version = '1.0'
+ s.source = 'http://gems.rubyforge.org'
+ end
+
+ spec2 = spec1.dup
+ spec2.source = "http://gems.github.com"
+
+ spec1.should_not == spec2
+ end
+
+ it "can set a source that is already a URI" do
+ source = URI.parse("http://foo")
+ spec = Gem::Specification.new
+ spec.source = source
+ spec.source.should == source
+ end
+
+ it "requires a valid URI for the source" do
+ spec = Gem::Specification.new
+ lambda { spec.source = "fail" }.should raise_error(ArgumentError)
+ end
+
+end
View
40 spec/spec_helper.rb
@@ -2,6 +2,46 @@
$:.push File.join(File.dirname(__FILE__), '..', 'gem_resolver', 'lib')
require "gem_resolver/builders"
require "bundler"
+require "pp"
+
+Spec::Matchers.create :match_gems do |expected|
+ match do |actual|
+ @_messages = []
+ @dump = {}
+
+ if actual.nil?
+ @_messages << "The result is nil"
+ next
+ end
+
+ actual.each do |spec|
+ unless spec.is_a?(Gem::Specification)
+ @_messages << "#{spec.gem_resolver_inspect} was expected to be a Gem::Specification, but got #{spec.class}"
+ next
+ end
+ @dump[spec.name.to_s] ||= []
+ @dump[spec.name.to_s] << spec.version.to_s
+ end
+
+ if @_messages.any?
+ @_messages.unshift "The gems #{actual.gem_resolver_inspect} were not structured as expected"
+ next false
+ end
+
+ unless @dump == expected
+ @_messages << "The source index was expected to have the gems:"
+ @_messages << expected.to_a.sort.pretty_inspect
+ @_messages << "but got:"
+ @_messages << @dump.to_a.sort.pretty_inspect
+ next false
+ end
+ true
+ end
+
+ failure_message_for_should do |actual|
+ @_messages.join("\n")
+ end
+end
Spec::Runner.configure do |config|
config.include GemResolver::Builders
Please sign in to comment.
Something went wrong with that request. Please try again.