2016-02-01 15:43:26 +03:00
|
|
|
# frozen_string_literal: true
|
2023-03-17 12:36:42 +03:00
|
|
|
|
2013-02-28 03:20:57 +04:00
|
|
|
class Gem::AvailableSet
|
2013-09-14 12:59:02 +04:00
|
|
|
include Enumerable
|
|
|
|
|
2013-02-28 03:20:57 +04:00
|
|
|
Tuple = Struct.new(:spec, :source)
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2014-02-04 04:48:31 +04:00
|
|
|
attr_accessor :remote # :nodoc:
|
|
|
|
|
2013-02-28 03:20:57 +04:00
|
|
|
def initialize
|
|
|
|
@set = []
|
|
|
|
@sorted = nil
|
2014-02-04 04:48:31 +04:00
|
|
|
@remote = true
|
2013-02-28 03:20:57 +04:00
|
|
|
end
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2013-02-28 03:20:57 +04:00
|
|
|
attr_reader :set
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2013-02-28 03:20:57 +04:00
|
|
|
def add(spec, source)
|
|
|
|
@set << Tuple.new(spec, source)
|
|
|
|
@sorted = nil
|
|
|
|
self
|
|
|
|
end
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2013-02-28 03:20:57 +04:00
|
|
|
def <<(o)
|
|
|
|
case o
|
|
|
|
when Gem::AvailableSet
|
|
|
|
s = o.set
|
|
|
|
when Array
|
|
|
|
s = o.map do |sp,so|
|
2023-03-16 07:08:50 +03:00
|
|
|
if !sp.is_a?(Gem::Specification) || !so.is_a?(Gem::Source)
|
2013-02-28 03:20:57 +04:00
|
|
|
raise TypeError, "Array must be in [[spec, source], ...] form"
|
2012-11-29 10:52:18 +04:00
|
|
|
end
|
2013-02-28 03:20:57 +04:00
|
|
|
|
|
|
|
Tuple.new(sp,so)
|
2012-11-29 10:52:18 +04:00
|
|
|
end
|
2013-02-28 03:20:57 +04:00
|
|
|
else
|
|
|
|
raise TypeError, "must be a Gem::AvailableSet"
|
|
|
|
end
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2013-02-28 03:20:57 +04:00
|
|
|
@set += s
|
|
|
|
@sorted = nil
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2013-02-28 03:20:57 +04:00
|
|
|
self
|
|
|
|
end
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2013-09-14 12:59:02 +04:00
|
|
|
##
|
|
|
|
# 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
|
|
|
|
|
2013-02-28 03:20:57 +04:00
|
|
|
def empty?
|
|
|
|
@set.empty?
|
|
|
|
end
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2013-02-28 03:20:57 +04:00
|
|
|
def all_specs
|
2023-03-16 06:57:49 +03:00
|
|
|
@set.map(&:spec)
|
2013-02-28 03:20:57 +04:00
|
|
|
end
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2013-02-28 03:20:57 +04:00
|
|
|
def match_platform!
|
2020-12-08 10:33:39 +03:00
|
|
|
@set.reject! {|t| !Gem::Platform.match_spec?(t.spec) }
|
2013-02-28 03:20:57 +04:00
|
|
|
@sorted = nil
|
|
|
|
self
|
|
|
|
end
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2013-02-28 03:20:57 +04:00
|
|
|
def sorted
|
|
|
|
@sorted ||= @set.sort do |a,b|
|
|
|
|
i = b.spec <=> a.spec
|
|
|
|
i != 0 ? i : (a.source <=> b.source)
|
2012-11-29 10:52:18 +04:00
|
|
|
end
|
2013-02-28 03:20:57 +04:00
|
|
|
end
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2013-02-28 03:20:57 +04:00
|
|
|
def size
|
|
|
|
@set.size
|
|
|
|
end
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2013-02-28 03:20:57 +04:00
|
|
|
def source_for(spec)
|
2020-06-10 20:46:05 +03:00
|
|
|
f = @set.find {|t| t.spec == spec }
|
2013-02-28 03:20:57 +04:00
|
|
|
f.source
|
|
|
|
end
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2013-09-14 12:59:02 +04:00
|
|
|
##
|
|
|
|
# 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.
|
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
def to_request_set(development = :none)
|
2013-09-14 12:59:02 +04:00
|
|
|
request_set = Gem::RequestSet.new
|
2023-03-16 07:38:45 +03:00
|
|
|
request_set.development = development == :all
|
2013-09-14 12:59:02 +04:00
|
|
|
|
|
|
|
each_spec do |spec|
|
|
|
|
request_set.always_install << spec
|
|
|
|
|
|
|
|
request_set.gem spec.name, spec.version
|
|
|
|
request_set.import spec.development_dependencies if
|
2023-03-16 07:38:45 +03:00
|
|
|
development == :shallow
|
2013-09-14 12:59:02 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
request_set
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
2013-11-19 04:34:13 +04:00
|
|
|
# Used by the Resolver, the protocol to use a AvailableSet as a
|
2013-09-14 12:59:02 +04:00
|
|
|
# search Set.
|
|
|
|
|
|
|
|
def find_all(req)
|
|
|
|
dep = req.dependency
|
|
|
|
|
|
|
|
match = @set.find_all do |t|
|
2014-09-14 07:30:02 +04:00
|
|
|
dep.match? t.spec
|
2013-09-14 12:59:02 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
match.map do |t|
|
2013-11-25 23:14:49 +04:00
|
|
|
Gem::Resolver::LocalSpecification.new(self, t.spec, t.source)
|
2013-09-14 12:59:02 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def prefetch(reqs)
|
|
|
|
end
|
|
|
|
|
2013-02-28 03:20:57 +04:00
|
|
|
def pick_best!
|
|
|
|
return self if empty?
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2013-02-28 03:20:57 +04:00
|
|
|
@set = [sorted.first]
|
|
|
|
@sorted = nil
|
|
|
|
self
|
|
|
|
end
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2013-02-28 03:20:57 +04:00
|
|
|
def remove_installed!(dep)
|
2023-03-16 04:46:45 +03:00
|
|
|
@set.reject! do |_t|
|
2013-02-28 03:20:57 +04:00
|
|
|
# already locally installed
|
|
|
|
Gem::Specification.any? do |installed_spec|
|
2022-08-09 05:16:07 +03:00
|
|
|
dep.name == installed_spec.name &&
|
|
|
|
dep.requirement.satisfied_by?(installed_spec.version)
|
2012-11-29 10:52:18 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-28 03:20:57 +04:00
|
|
|
@sorted = nil
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def inject_into_list(dep_list)
|
2020-06-10 20:46:05 +03:00
|
|
|
@set.each {|t| dep_list.add t.spec }
|
2012-11-29 10:52:18 +04:00
|
|
|
end
|
|
|
|
end
|