aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/source
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-09 23:21:36 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-09 23:21:36 +0000
commit47f0248b0858898dd24d1e654cedf174059ca677 (patch)
tree493e84160f8609db408d88349f0624a3ff92c3c2 /lib/rubygems/source
parentcd9f9e471977447a991ced4ea38efb2309459ef5 (diff)
downloadruby-47f0248b0858898dd24d1e654cedf174059ca677.tar.gz
* lib/rubygems: Import RubyGems 2.1
* test/rubygems: Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/source')
-rw-r--r--lib/rubygems/source/installed.rb28
-rw-r--r--lib/rubygems/source/local.rb122
-rw-r--r--lib/rubygems/source/specific_file.rb28
3 files changed, 178 insertions, 0 deletions
diff --git a/lib/rubygems/source/installed.rb b/lib/rubygems/source/installed.rb
new file mode 100644
index 0000000000..7709778791
--- /dev/null
+++ b/lib/rubygems/source/installed.rb
@@ -0,0 +1,28 @@
+class Gem::Source::Installed < Gem::Source
+
+ def initialize
+ end
+
+ ##
+ # Installed sources sort before all other sources
+
+ def <=> other
+ case other
+ when Gem::Source::Installed then
+ 0
+ when Gem::Source then
+ 1
+ else
+ nil
+ end
+ end
+
+ ##
+ # We don't need to download an installed gem
+
+ def download spec, path
+ nil
+ end
+
+end
+
diff --git a/lib/rubygems/source/local.rb b/lib/rubygems/source/local.rb
new file mode 100644
index 0000000000..7392ff0e8e
--- /dev/null
+++ b/lib/rubygems/source/local.rb
@@ -0,0 +1,122 @@
+require 'rubygems/source'
+
+class Gem::Source::Local < Gem::Source
+ def initialize
+ @uri = nil
+ end
+
+ ##
+ # Local sorts before Gem::Source and after Gem::Source::Installed
+
+ def <=> other
+ case other
+ when Gem::Source::Installed then
+ -1
+ when Gem::Source::Local then
+ 0
+ when Gem::Source then
+ 1
+ else
+ nil
+ end
+ end
+
+ def inspect # :nodoc:
+ "#<%s specs: %p>" % [self.class, @specs.keys]
+ end
+
+ def load_specs(type)
+ names = []
+
+ @specs = {}
+
+ Dir["*.gem"].each do |file|
+ begin
+ pkg = Gem::Package.new(file)
+ rescue SystemCallError, Gem::Package::FormatError
+ # ignore
+ else
+ tup = pkg.spec.name_tuple
+ @specs[tup] = [File.expand_path(file), pkg]
+
+ case type
+ when :released
+ unless pkg.spec.version.prerelease?
+ names << pkg.spec.name_tuple
+ end
+ when :prerelease
+ if pkg.spec.version.prerelease?
+ names << pkg.spec.name_tuple
+ end
+ when :latest
+ tup = pkg.spec.name_tuple
+
+ cur = names.find { |x| x.name == tup.name }
+ if !cur
+ names << tup
+ elsif cur.version < tup.version
+ names.delete cur
+ names << tup
+ end
+ else
+ names << pkg.spec.name_tuple
+ end
+ end
+ end
+
+ names
+ end
+
+ def find_gem(gem_name, version=Gem::Requirement.default,
+ prerelease=false)
+ load_specs :complete
+
+ found = []
+
+ @specs.each do |n, data|
+ if n.name == gem_name
+ s = data[1].spec
+
+ if version.satisfied_by?(s.version)
+ if prerelease
+ found << s
+ elsif !s.version.prerelease?
+ found << s
+ end
+ end
+ end
+ end
+
+ found.sort_by { |s| s.version }.last
+ end
+
+ def fetch_spec(name)
+ load_specs :complete
+
+ if data = @specs[name]
+ data.last.spec
+ else
+ raise Gem::Exception, "Unable to find spec for '#{name}'"
+ end
+ end
+
+ def download(spec, cache_dir=nil)
+ load_specs :complete
+
+ @specs.each do |name, data|
+ return data[0] if data[1].spec == spec
+ end
+
+ raise Gem::Exception, "Unable to find file for '#{spec.full_name}'"
+ end
+
+ def pretty_print q # :nodoc:
+ q.group 2, '[Local gems:', ']' do
+ q.breakable
+ q.seplist @specs.keys do |v|
+ q.text v.full_name
+ end
+ end
+ end
+
+end
diff --git a/lib/rubygems/source/specific_file.rb b/lib/rubygems/source/specific_file.rb
new file mode 100644
index 0000000000..d296e617cc
--- /dev/null
+++ b/lib/rubygems/source/specific_file.rb
@@ -0,0 +1,28 @@
+class Gem::Source::SpecificFile < Gem::Source
+ def initialize(file)
+ @uri = nil
+ @path = ::File.expand_path(file)
+
+ @package = Gem::Package.new @path
+ @spec = @package.spec
+ @name = @spec.name_tuple
+ end
+
+ attr_reader :spec
+
+ def load_specs(*a)
+ [@name]
+ end
+
+ def fetch_spec(name)
+ return @spec if name == @name
+ raise Gem::Exception, "Unable to find '#{name}'"
+ @spec
+ end
+
+ def download(spec, dir=nil)
+ return @path if spec == @spec
+ raise Gem::Exception, "Unable to download '#{spec.full_name}'"
+ end
+
+end