From 9694bb8cac12969300692dac5a1cf7aa4e3a46cd Mon Sep 17 00:00:00 2001 From: drbrain Date: Thu, 29 Nov 2012 06:52:18 +0000 Subject: * lib/rubygems*: Updated to RubyGems 2.0 * test/rubygems*: ditto. * common.mk (prelude): Updated for RubyGems 2.0 source rearrangement. * tool/change_maker.rb: Allow invalid UTF-8 characters in source files. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rubygems/dependency.rb | 71 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 10 deletions(-) (limited to 'lib/rubygems/dependency.rb') diff --git a/lib/rubygems/dependency.rb b/lib/rubygems/dependency.rb index 0caf65c6c4..217189bf8e 100644 --- a/lib/rubygems/dependency.rb +++ b/lib/rubygems/dependency.rb @@ -1,8 +1,8 @@ -require "rubygems/requirement" - ## # The Dependency class holds a Gem name and a Gem::Requirement. +require "rubygems/requirement" + class Gem::Dependency ## @@ -11,6 +11,9 @@ class Gem::Dependency # When this list is updated, be sure to change # Gem::Specification::CURRENT_SPECIFICATION_VERSION as well. + # REFACTOR: This type of constant, TYPES, indicates we might want + # two classes, used via inheretance or duck typing. + TYPES = [ :development, :runtime, @@ -32,18 +35,23 @@ class Gem::Dependency # :runtime. def initialize name, *requirements - if Regexp === name then + case name + when String then # ok + when Regexp then msg = ["NOTE: Dependency.new w/ a regexp is deprecated.", "Dependency.new called from #{Gem.location_of_caller.join(":")}"] warn msg.join("\n") unless Gem::Deprecate.skip + else + raise ArgumentError, + "dependency name must be a String, was #{name.inspect}" end type = Symbol === requirements.last ? requirements.pop : :runtime requirements = requirements.first if 1 == requirements.length # unpack unless TYPES.include? type - raise ArgumentError, "Valid types are #{TYPES.inspect}, " - + "not #{type.inspect}" + raise ArgumentError, "Valid types are #{TYPES.inspect}, " + + "not #{type.inspect}" end @name = name @@ -66,8 +74,13 @@ class Gem::Dependency end def inspect # :nodoc: - "<%s type=%p name=%p requirements=%p>" % - [self.class, self.type, self.name, requirement.to_s] + if @prerelease + "<%s type=%p name=%p requirements=%p prerelease=ok>" % + [self.class, self.type, self.name, requirement.to_s] + else + "<%s type=%p name=%p requirements=%p>" % + [self.class, self.type, self.name, requirement.to_s] + end end ## @@ -77,6 +90,14 @@ class Gem::Dependency @prerelease || requirement.prerelease? end + ## + # Is this dependency simply asking for the latest version + # of a gem? + + def latest_version? + @requirement.none? + end + def pretty_print q # :nodoc: q.group 1, 'Gem::Dependency.new(', ')' do q.pp name @@ -113,6 +134,8 @@ class Gem::Dependency # Children, define explicit marshal and unmarshal behavior for # public classes. Marshal formats are part of your public API. + # REFACTOR: See above + if defined?(@version_requirement) && @version_requirement version = @version_requirement.instance_variable_get :@version @version_requirement = nil @@ -122,6 +145,7 @@ class Gem::Dependency @requirement = @version_requirements if defined?(@version_requirements) end + # DOC: this method needs documentation or :nodoc''d def requirements_list requirement.as_list end @@ -179,13 +203,24 @@ class Gem::Dependency requirement.satisfied_by? version end - def match? name, version + # DOC: this method needs either documented or :nodoc'd + + def match? obj, version=nil + if !version + name = obj.name + version = obj.version + else + name = obj + end + return false unless self.name === name return true if requirement.none? requirement.satisfied_by? Gem::Version.new(version) end + # DOC: this method needs either documented or :nodoc'd + def matches_spec? spec return false unless name === spec.name return true if requirement.none? @@ -212,6 +247,8 @@ class Gem::Dependency self.class.new name, self_req.as_list.concat(other_req.as_list) end + # DOC: this method needs either documented or :nodoc'd + def matching_specs platform_only = false matches = Gem::Specification.find_all { |spec| self.name === spec.name and # TODO: == instead of === @@ -234,14 +271,26 @@ class Gem::Dependency @requirement.specific? end + # DOC: this method needs either documented or :nodoc'd + 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}]" + specs = Gem::Specification.find_all { |s| + s.name == name + }.map { |x| x.full_name } + + if specs.empty? + total = Gem::Specification.to_a.size + error = Gem::LoadError.new \ + "Could not find '#{name}' (#{requirement}) among #{total} total gem(s)" + else + error = Gem::LoadError.new \ + "Could not find '#{name}' (#{requirement}) - did find: [#{specs.join ','}]" + end error.name = self.name error.requirement = self.requirement raise error @@ -252,6 +301,8 @@ class Gem::Dependency matches end + # DOC: this method needs either documented or :nodoc'd + def to_spec matches = self.to_specs -- cgit v1.2.1