aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/dependency.rb
diff options
context:
space:
mode:
authorryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-03-01 09:41:32 +0000
committerryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-03-01 09:41:32 +0000
commit25a9b62d45ddd60a231272567c7dda9337da9b62 (patch)
treee72ba4c9c01cba5fb510eb1eafaba76d998baf4c /lib/rubygems/dependency.rb
parent86bb0af7ea3b50f72e6845a6f5f64cb1b23fd279 (diff)
downloadruby-25a9b62d45ddd60a231272567c7dda9337da9b62.tar.gz
Import rubygems 1.6.0 (released version @ 58d8a0b9)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30996 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/dependency.rb')
-rw-r--r--lib/rubygems/dependency.rb41
1 files changed, 33 insertions, 8 deletions
diff --git a/lib/rubygems/dependency.rb b/lib/rubygems/dependency.rb
index 4c61b6563e..e4d1bfffe8 100644
--- a/lib/rubygems/dependency.rb
+++ b/lib/rubygems/dependency.rb
@@ -33,11 +33,6 @@ class Gem::Dependency
attr_writer :prerelease
##
- # Dependency type.
-
- attr_reader :type
-
- ##
# Constructs a dependency with +name+ and +requirements+. The last
# argument can optionally be the dependency type, which defaults to
# <tt>:runtime</tt>.
@@ -72,7 +67,7 @@ class Gem::Dependency
def inspect # :nodoc:
"<%s type=%p name=%p requirements=%p>" %
- [self.class, @type, @name, requirement.to_s]
+ [self.class, self.type, self.name, requirement.to_s]
end
##
@@ -132,7 +127,18 @@ class Gem::Dependency
end
def to_s # :nodoc:
- "#{name} (#{requirement}, #{type})"
+ if type != :runtime then
+ "#{name} (#{requirement}, #{type})"
+ else
+ "#{name} (#{requirement})"
+ end
+ end
+
+ ##
+ # Dependency type.
+
+ def type
+ @type ||= :runtime
end
def == other # :nodoc:
@@ -146,7 +152,7 @@ class Gem::Dependency
# Dependencies are ordered by name.
def <=> other
- @name <=> other.name
+ self.name <=> other.name
end
##
@@ -187,5 +193,24 @@ class Gem::Dependency
requirement.satisfied_by?(spec.version)
end
+ ##
+ # Merges the requirements of +other+ into this dependency
+
+ def merge other
+ unless name == other.name then
+ raise ArgumentError,
+ "#{self} and #{other} have different names"
+ end
+
+ default = Gem::Requirement.default
+ self_req = self.requirement
+ other_req = other.requirement
+
+ return self.class.new name, self_req if other_req == default
+ return self.class.new name, other_req if self_req == default
+
+ self.class.new name, self_req.as_list.concat(other_req.as_list)
+ end
+
end