1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Update to RubyGems 1.3.4 r2223

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
drbrain 2009-06-09 21:38:59 +00:00
parent a6afbaeb3b
commit 31c94ffeb5
126 changed files with 7610 additions and 3747 deletions

View file

@ -4,12 +4,14 @@
# See LICENSE.txt for permissions.
#++
require 'rubygems'
require 'rubygems/user_interaction'
require 'rubygems/specification'
# :stopdoc:
module Gem
autoload(:SpecFetcher, 'rubygems/spec_fetcher')
autoload :SpecFetcher, 'rubygems/spec_fetcher'
end
# :startdoc:
##
# The SourceIndex object indexes all the gems available from a
@ -28,7 +30,7 @@ class Gem::SourceIndex
include Gem::UserInteraction
attr_reader :gems # :nodoc:
attr_reader :gems, :prerelease_gems # :nodoc:
##
# Directories to use to refresh this SourceIndex when calling refresh!
@ -81,13 +83,15 @@ class Gem::SourceIndex
# loaded spec.
def load_specification(file_name)
begin
spec_code = if RUBY_VERSION < '1.9' then
File.read file_name
else
File.read file_name, :encoding => 'UTF-8'
end.untaint
return nil unless file_name and File.exist? file_name
spec_code = if RUBY_VERSION < '1.9' then
File.read file_name
else
File.read file_name, :encoding => 'UTF-8'
end.untaint
begin
gemspec = eval spec_code, binding, file_name
if gemspec.is_a?(Gem::Specification)
@ -104,23 +108,32 @@ class Gem::SourceIndex
alert_warning "#{e.inspect}\n#{spec_code}"
alert_warning "Invalid .gemspec format in '#{file_name}'"
end
return nil
end
end
##
# Constructs a source index instance from the provided
# specifications
#
# specifications::
# [Hash] hash of [Gem name, Gem::Specification] pairs
# Constructs a source index instance from the provided specifications, which
# is a Hash of gem full names and Gem::Specifications.
#--
# TODO merge @gems and @prerelease_gems and provide a separate method
# #prerelease_gems
def initialize(specifications={})
@gems = specifications
@gems, @prerelease_gems = [{}, {}]
specifications.each{ |full_name, spec| add_spec spec }
@spec_dirs = nil
end
##
# Both regular and prerelease gems
def all_gems
@gems.merge @prerelease_gems
end
##
# Reconstruct the source index from the specifications in +spec_dirs+.
@ -170,14 +183,29 @@ class Gem::SourceIndex
result[name] << spec
end
# TODO: why is this a hash while @gems is an array? Seems like
# structural similarity would be good.
result.values.flatten
end
##
# An array including only the prerelease gemspecs
def prerelease_specs
@prerelease_gems.values
end
##
# Add a gem specification to the source index.
def add_spec(gem_spec)
@gems[gem_spec.full_name] = gem_spec
def add_spec(gem_spec, name = gem_spec.full_name)
# No idea why, but the Indexer wants to insert them using original_name
# instead of full_name. So we make it an optional arg.
if gem_spec.version.prerelease?
@prerelease_gems[name] = gem_spec
else
@gems[name] = gem_spec
end
end
##
@ -193,7 +221,11 @@ class Gem::SourceIndex
# Remove a gem specification named +full_name+.
def remove_spec(full_name)
@gems.delete(full_name)
if @gems.key? full_name then
@gems.delete full_name
else
@prerelease_gems.delete full_name
end
end
##
@ -215,18 +247,18 @@ class Gem::SourceIndex
# change in the index.
def index_signature
require 'rubygems/digest/sha2'
require 'digest'
Gem::SHA256.new.hexdigest(@gems.keys.sort.join(',')).to_s
Digest::SHA256.new.hexdigest(@gems.keys.sort.join(',')).to_s
end
##
# The signature for the given gem specification.
def gem_signature(gem_full_name)
require 'rubygems/digest/sha2'
require 'digest'
Gem::SHA256.new.hexdigest(@gems[gem_full_name].to_yaml).to_s
Digest::SHA256.new.hexdigest(@gems[gem_full_name].to_yaml).to_s
end
def size
@ -238,7 +270,7 @@ class Gem::SourceIndex
# Find a gem by an exact match on the short name.
def find_name(gem_name, version_requirement = Gem::Requirement.default)
dep = Gem::Dependency.new(/^#{gem_name}$/, version_requirement)
dep = Gem::Dependency.new gem_name, version_requirement
search dep
end
@ -257,7 +289,7 @@ class Gem::SourceIndex
# TODO - Remove support and warning for legacy arguments after 2008/11
unless Gem::Dependency === gem_pattern
warn "#{Gem.location_of_caller.join ':'}:Warning: Gem::SourceIndex#search support for #{gem_pattern.class} patterns is deprecated"
warn "#{Gem.location_of_caller.join ':'}:Warning: Gem::SourceIndex#search support for #{gem_pattern.class} patterns is deprecated, use #find_name"
end
case gem_pattern
@ -282,7 +314,7 @@ class Gem::SourceIndex
version_requirement = Gem::Requirement.create version_requirement
end
specs = @gems.values.select do |spec|
specs = all_gems.values.select do |spec|
spec.name =~ gem_pattern and
version_requirement.satisfied_by? spec.version
end
@ -376,7 +408,7 @@ class Gem::SourceIndex
end
def ==(other) # :nodoc:
self.class === other and @gems == other.gems
self.class === other and @gems == other.gems
end
def dump
@ -545,15 +577,15 @@ class Gem::SourceIndex
end
# :stopdoc:
module Gem
# :stopdoc:
##
# Cache is an alias for SourceIndex to allow older YAMLized source index
# objects to load properly.
Cache = SourceIndex
# :startdoc:
end
# :startdoc: