summaryrefslogtreecommitdiff
path: root/lib/rubygems/source_index.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/source_index.rb')
-rw-r--r--lib/rubygems/source_index.rb43
1 files changed, 20 insertions, 23 deletions
diff --git a/lib/rubygems/source_index.rb b/lib/rubygems/source_index.rb
index 759718d45c..2df28d9561 100644
--- a/lib/rubygems/source_index.rb
+++ b/lib/rubygems/source_index.rb
@@ -4,8 +4,6 @@
# See LICENSE.txt for permissions.
#++
-require 'forwardable'
-
require 'rubygems'
require 'rubygems/user_interaction'
require 'rubygems/specification'
@@ -23,7 +21,6 @@ module Gem
# YAMLized source index objects to load properly.
#
class SourceIndex
- extend Forwardable
include Enumerable
@@ -186,40 +183,40 @@ module Gem
Gem::SHA256.new.hexdigest(@gems[gem_full_name].to_yaml).to_s
end
- def_delegators :@gems, :size, :length
+ def size
+ @gems.size
+ end
+ alias length size
# Find a gem by an exact match on the short name.
def find_name(gem_name, version_requirement = Gem::Requirement.default)
search(/^#{gem_name}$/, version_requirement)
end
- # Search for a gem by short name pattern and optional version
- #
- # gem_name::
- # [String] a partial for the (short) name of the gem, or
- # [Regex] a pattern to match against the short name
- # version_requirement::
- # [String | default=Gem::Requirement.default] version to
- # find
- # return::
- # [Array] list of Gem::Specification objects in sorted (version)
- # order. Empty if not found.
+ # Search for a gem by Gem::Dependency +gem_pattern+. If +only_platform+
+ # is true, only gems matching Gem::Platform.local will be returned. An
+ # Array of matching Gem::Specification objects is returned.
#
- def search(gem_pattern, platform_only_or_version_req = false)
+ # For backwards compatibility, a String or Regexp pattern may be passed as
+ # +gem_pattern+, and a Gem::Requirement for +platform_only+. This
+ # behavior is deprecated and will be removed.
+ def search(gem_pattern, platform_only = false)
version_requirement = nil
only_platform = false
- case gem_pattern
+ case gem_pattern # TODO warn after 2008/03, remove three months after
when Regexp then
- version_requirement = platform_only_or_version_req ||
- Gem::Requirement.default
+ version_requirement = platform_only || Gem::Requirement.default
when Gem::Dependency then
- only_platform = platform_only_or_version_req
+ only_platform = platform_only
version_requirement = gem_pattern.version_requirements
- gem_pattern = gem_pattern.name.empty? ? // : /^#{gem_pattern.name}$/
+ gem_pattern = if gem_pattern.name.empty? then
+ //
+ else
+ /^#{Regexp.escape gem_pattern.name}$/
+ end
else
- version_requirement = platform_only_or_version_req ||
- Gem::Requirement.default
+ version_requirement = platform_only || Gem::Requirement.default
gem_pattern = /#{gem_pattern}/i
end