aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/source_index.rb
diff options
context:
space:
mode:
authorryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-01 03:45:05 +0000
committerryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-01 03:45:05 +0000
commitd22130922e7842226d38d59680e4bbb48a28a5f0 (patch)
tree39594d3a14641dd5488a99a5e633239296fa5742 /lib/rubygems/source_index.rb
parent4752539e3f3e563d559732c52424206bd6f12dbd (diff)
downloadruby-d22130922e7842226d38d59680e4bbb48a28a5f0.tar.gz
Import rubygems 1.8.5 (released @ 137c80f)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/source_index.rb')
-rw-r--r--lib/rubygems/source_index.rb172
1 files changed, 111 insertions, 61 deletions
diff --git a/lib/rubygems/source_index.rb b/lib/rubygems/source_index.rb
index a6733fac31..74ad5476d4 100644
--- a/lib/rubygems/source_index.rb
+++ b/lib/rubygems/source_index.rb
@@ -11,6 +11,7 @@
#++
require 'rubygems/specification'
+require 'rubygems/deprecate'
##
# The SourceIndex object indexes all the gems available from a
@@ -34,79 +35,86 @@ class Gem::SourceIndex
attr_accessor :spec_dirs
- class << self
- ##
- # Factory method to construct a source index instance for a given
- # path.
- #
- # deprecated::
- # If supplied, from_installed_gems will act just like
- # +from_gems_in+. This argument is deprecated and is provided
- # just for backwards compatibility, and should not generally
- # be used.
- #
- # return::
- # SourceIndex instance
-
- def from_installed_gems(*deprecated)
- if deprecated.empty?
- from_gems_in(*installed_spec_directories)
- else
- from_gems_in(*deprecated) # HACK warn
- end
+ ##
+ # Factory method to construct a source index instance for a given
+ # path.
+ #
+ # deprecated::
+ # If supplied, from_installed_gems will act just like
+ # +from_gems_in+. This argument is deprecated and is provided
+ # just for backwards compatibility, and should not generally
+ # be used.
+ #
+ # return::
+ # SourceIndex instance
+
+ def self.from_installed_gems(*deprecated)
+ if deprecated.empty?
+ from_gems_in(*installed_spec_directories)
+ else
+ warn "NOTE: from_installed_gems(arg) is deprecated. From #{caller.first}"
+ from_gems_in(*deprecated) # HACK warn
end
+ end
- ##
- # Returns a list of directories from Gem.path that contain specifications.
+ ##
+ # Returns a list of directories from Gem.path that contain specifications.
- def installed_spec_directories
- Gem.path.collect { |dir| File.join(dir, "specifications") }
- end
+ def self.installed_spec_directories
+ # TODO: move to Gem::Utils
+ Gem.path.collect { |dir| File.join(dir, "specifications") }
+ end
- ##
- # Creates a new SourceIndex from the ruby format gem specifications in
- # +spec_dirs+.
+ ##
+ # Creates a new SourceIndex from the ruby format gem specifications in
+ # +spec_dirs+.
- def from_gems_in(*spec_dirs)
- source_index = new
- source_index.spec_dirs = spec_dirs
- source_index.refresh!
- end
+ def self.from_gems_in(*spec_dirs)
+ new spec_dirs
+ end
- ##
- # Loads a ruby-format specification from +file_name+ and returns the
- # loaded spec.
+ ##
+ # Loads a ruby-format specification from +file_name+ and returns the
+ # loaded spec.
- def load_specification(file_name)
- Gem::Specification.load file_name
+ def self.load_specification(file_name)
+ Deprecate.skip_during do
+ Gem::Specification.load Gem::Path.new(file_name)
end
-
end
##
# 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={})
+ def initialize specs_or_dirs = []
@gems = {}
- specifications.each{ |full_name, spec| add_spec spec }
@spec_dirs = nil
+
+ case specs_or_dirs
+ when Hash then
+ specs_or_dirs.each do |full_name, spec|
+ add_spec spec
+ end
+ when Array, String then
+ self.spec_dirs = Array(specs_or_dirs)
+ refresh!
+ else
+ arg = specs_or_dirs.inspect
+ warn "NOTE: SourceIndex.new(#{arg}) is deprecated; From #{caller.first}."
+ end
end
- # TODO: remove method
def all_gems
- @gems
+ gems
end
def prerelease_gems
- @gems.reject{ |name, gem| !gem.version.prerelease? }
+ @gems.reject { |name, gem| !gem.version.prerelease? }
end
def released_gems
- @gems.reject{ |name, gem| gem.version.prerelease? }
+ @gems.reject { |name, gem| gem.version.prerelease? }
end
##
@@ -116,10 +124,12 @@ class Gem::SourceIndex
@gems.clear
spec_dirs.reverse_each do |spec_dir|
- spec_files = Dir.glob File.join(spec_dir, '*.gemspec')
+ spec_files = Dir[File.join(spec_dir, "*.gemspec")]
spec_files.each do |spec_file|
- gemspec = Gem::Specification.load spec_file
+ gemspec = Deprecate.skip_during do
+ Gem::Specification.load spec_file
+ end
add_spec gemspec if gemspec
end
end
@@ -159,8 +169,6 @@ 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
@@ -246,7 +254,10 @@ class Gem::SourceIndex
def find_name(gem_name, requirement = Gem::Requirement.default)
dep = Gem::Dependency.new gem_name, requirement
- search dep
+
+ Deprecate.skip_during do
+ search dep
+ end
end
##
@@ -258,9 +269,9 @@ class Gem::SourceIndex
# +gem_pattern+, and a Gem::Requirement for +platform_only+. This
# behavior is deprecated and will be removed.
- def search(gem_pattern, platform_only = false)
+ def search(gem_pattern, platform_or_requirement = false)
requirement = nil
- only_platform = false
+ only_platform = false # FIX: WTF is this?!?
# TODO - Remove support and warning for legacy arguments after 2008/11
unless Gem::Dependency === gem_pattern
@@ -269,9 +280,9 @@ class Gem::SourceIndex
case gem_pattern
when Regexp then
- requirement = platform_only || Gem::Requirement.default
+ requirement = platform_or_requirement || Gem::Requirement.default
when Gem::Dependency then
- only_platform = platform_only
+ only_platform = platform_or_requirement
requirement = gem_pattern.requirement
gem_pattern = if Regexp === gem_pattern.name then
@@ -282,7 +293,7 @@ class Gem::SourceIndex
/^#{Regexp.escape gem_pattern.name}$/
end
else
- requirement = platform_only || Gem::Requirement.default
+ requirement = platform_or_requirement || Gem::Requirement.default
gem_pattern = /#{gem_pattern}/i
end
@@ -290,7 +301,7 @@ class Gem::SourceIndex
requirement = Gem::Requirement.create requirement
end
- specs = all_gems.values.select do |spec|
+ specs = @gems.values.select do |spec|
spec.name =~ gem_pattern and
requirement.satisfied_by? spec.version
end
@@ -343,7 +354,6 @@ class Gem::SourceIndex
def dump
Marshal.dump(self)
end
-
end
# :stopdoc:
@@ -356,5 +366,45 @@ module Gem
Cache = SourceIndex
end
-# :startdoc:
+class Gem::SourceIndex
+ extend Deprecate
+
+ deprecate :all_gems, :none, 2011, 10
+
+ deprecate :==, :none, 2011, 11 # noisy
+ deprecate :add_specs, :none, 2011, 11 # noisy
+ deprecate :each, :none, 2011, 11
+ deprecate :gems, :none, 2011, 11
+ deprecate :load_gems_in, :none, 2011, 11
+ deprecate :refresh!, :none, 2011, 11
+ deprecate :spec_dirs=, "Specification.dirs=", 2011, 11 # noisy
+ deprecate :add_spec, "Specification.add_spec", 2011, 11
+ deprecate :find_name, "Specification.find_by_name", 2011, 11
+ deprecate :gem_signature, :none, 2011, 11
+ deprecate :index_signature, :none, 2011, 11
+ deprecate :initialize, :none, 2011, 11
+ deprecate :latest_specs, "Specification.latest_specs", 2011, 11
+ deprecate :length, "Specification.all.length", 2011, 11
+ deprecate :outdated, :none, 2011, 11
+ deprecate :prerelease_gems, :none, 2011, 11
+ deprecate :prerelease_specs, :none, 2011, 11
+ deprecate :released_gems, :none, 2011, 11
+ deprecate :released_specs, :none, 2011, 11
+ deprecate :remove_spec, "Specification.remove_spec", 2011, 11
+ deprecate :search, :none, 2011, 11
+ deprecate :size, "Specification.all.size", 2011, 11
+ deprecate :spec_dirs, "Specification.dirs", 2011, 11
+ deprecate :specification, "Specification.find", 2011, 11
+
+ class << self
+ extend Deprecate
+
+ deprecate :from_gems_in, :none, 2011, 10
+ deprecate :from_installed_gems, :none, 2011, 10
+ deprecate :installed_spec_directories, "Specification.dirs", 2011, 11
+ deprecate :load_specification, :none, 2011, 10
+ end
+end
+
+# :startdoc: