aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/dependency.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/dependency.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/dependency.rb')
-rw-r--r--lib/rubygems/dependency.rb52
1 files changed, 51 insertions, 1 deletions
diff --git a/lib/rubygems/dependency.rb b/lib/rubygems/dependency.rb
index e4d1bfffe8..1261154fe9 100644
--- a/lib/rubygems/dependency.rb
+++ b/lib/rubygems/dependency.rb
@@ -38,6 +38,12 @@ class Gem::Dependency
# <tt>:runtime</tt>.
def initialize name, *requirements
+ if Regexp === name then
+ msg = ["NOTE: Dependency.new w/ a regexp is deprecated.",
+ "Dependency.new called from #{Gem.location_of_caller.join(":")}"]
+ warn msg.join("\n") unless Deprecate.skip
+ end
+
type = Symbol === requirements.last ? requirements.pop : :runtime
requirements = requirements.first if 1 == requirements.length # unpack
@@ -212,5 +218,49 @@ class Gem::Dependency
self.class.new name, self_req.as_list.concat(other_req.as_list)
end
-end
+ def matching_specs platform_only = false
+ matches = Gem::Specification.find_all { |spec|
+ self.name === spec.name and # TODO: == instead of ===
+ requirement.satisfied_by? spec.version
+ }
+
+ if platform_only
+ matches.reject! { |spec|
+ not Gem::Platform.match spec.platform
+ }
+ end
+
+ matches = matches.sort_by { |s| s.sort_obj } # HACK: shouldn't be needed
+ end
+
+ ##
+ # True if the dependency will not always match the latest version.
+
+ def specific?
+ @requirement.specific?
+ end
+ def to_specs
+ matches = matching_specs true
+
+ # TODO: check Gem.activated_spec[self.name] in case matches falls outside
+
+ if matches.empty? then
+ specs = Gem::Specification.all_names.join ", "
+ error = Gem::LoadError.new "Could not find #{name} (#{requirement}) amongst [#{specs}]"
+ error.name = self.name
+ error.requirement = self.requirement
+ raise error
+ end
+
+ # TODO: any other resolver validations should go here
+
+ matches
+ end
+
+ def to_spec
+ matches = self.to_specs
+
+ matches.find { |spec| spec.activated? } or matches.last
+ end
+end