summaryrefslogtreecommitdiff
path: root/lib/rubygems/available_set.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/available_set.rb')
-rw-r--r--lib/rubygems/available_set.rb68
1 files changed, 68 insertions, 0 deletions
diff --git a/lib/rubygems/available_set.rb b/lib/rubygems/available_set.rb
index 80539feee9..bb0b3a3abe 100644
--- a/lib/rubygems/available_set.rb
+++ b/lib/rubygems/available_set.rb
@@ -1,4 +1,7 @@
class Gem::AvailableSet
+
+ include Enumerable
+
Tuple = Struct.new(:spec, :source)
def initialize
@@ -36,6 +39,28 @@ class Gem::AvailableSet
self
end
+ ##
+ # Yields each Tuple in this AvailableSet
+
+ def each
+ return enum_for __method__ unless block_given?
+
+ @set.each do |tuple|
+ yield tuple
+ end
+ end
+
+ ##
+ # Yields the Gem::Specification for each Tuple in this AvailableSet
+
+ def each_spec
+ return enum_for __method__ unless block_given?
+
+ each do |tuple|
+ yield tuple.spec
+ end
+ end
+
def empty?
@set.empty?
end
@@ -66,6 +91,49 @@ class Gem::AvailableSet
f.source
end
+ ##
+ # Converts this AvailableSet into a RequestSet that can be used to install
+ # gems.
+ #
+ # If +development+ is :none then no development dependencies are installed.
+ # Other options are :shallow for only direct development dependencies of the
+ # gems in this set or :all for all development dependencies.
+
+ def to_request_set development = :none
+ request_set = Gem::RequestSet.new
+ request_set.development = :all == development
+
+ each_spec do |spec|
+ request_set.always_install << spec
+
+ request_set.gem spec.name, spec.version
+ request_set.import spec.development_dependencies if
+ :shallow == development
+ end
+
+ request_set
+ end
+
+ ##
+ #
+ # Used by the DependencyResolver, the protocol to use a AvailableSet as a
+ # search Set.
+
+ def find_all(req)
+ dep = req.dependency
+
+ match = @set.find_all do |t|
+ dep.matches_spec? t.spec
+ end
+
+ match.map do |t|
+ Gem::DependencyResolver::InstalledSpecification.new(self, t.spec, t.source)
+ end
+ end
+
+ def prefetch(reqs)
+ end
+
def pick_best!
return self if empty?