2016-02-01 15:43:26 +03:00
|
|
|
# frozen_string_literal: true
|
2023-03-17 12:36:42 +03:00
|
|
|
|
2013-11-10 21:51:40 +04:00
|
|
|
##
|
|
|
|
# A set of gems from a gem dependencies lockfile.
|
|
|
|
|
2013-11-19 04:34:13 +04:00
|
|
|
class Gem::Resolver::LockSet < Gem::Resolver::Set
|
2013-11-10 21:51:40 +04:00
|
|
|
attr_reader :specs # :nodoc:
|
|
|
|
|
|
|
|
##
|
2014-09-14 07:30:02 +04:00
|
|
|
# Creates a new LockSet from the given +sources+
|
2013-11-10 21:51:40 +04:00
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
def initialize(sources)
|
2014-02-04 04:48:31 +04:00
|
|
|
super()
|
|
|
|
|
2014-09-14 07:30:02 +04:00
|
|
|
@sources = sources.map do |source|
|
|
|
|
Gem::Source::Lock.new source
|
|
|
|
end
|
|
|
|
|
2019-02-14 15:59:03 +03:00
|
|
|
@specs = []
|
2013-11-10 21:51:40 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Creates a new IndexSpecification in this set using the given +name+,
|
|
|
|
# +version+ and +platform+.
|
|
|
|
#
|
|
|
|
# The specification's set will be the current set, and the source will be
|
|
|
|
# the current set's source.
|
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
def add(name, version, platform) # :nodoc:
|
2013-11-10 21:51:40 +04:00
|
|
|
version = Gem::Version.new version
|
2016-02-01 15:43:26 +03:00
|
|
|
specs = [
|
2020-12-08 10:33:39 +03:00
|
|
|
Gem::Resolver::LockSpecification.new(self, name, version, @sources, platform),
|
2016-02-01 15:43:26 +03:00
|
|
|
]
|
2013-11-10 21:51:40 +04:00
|
|
|
|
2014-09-14 07:30:02 +04:00
|
|
|
@specs.concat specs
|
2013-12-08 05:22:39 +04:00
|
|
|
|
2014-09-14 07:30:02 +04:00
|
|
|
specs
|
2013-11-10 21:51:40 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Returns an Array of IndexSpecification objects matching the
|
|
|
|
# DependencyRequest +req+.
|
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
def find_all(req)
|
2013-11-10 21:51:40 +04:00
|
|
|
@specs.select do |spec|
|
2014-09-14 07:30:02 +04:00
|
|
|
req.match? spec
|
2013-11-10 21:51:40 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Loads a Gem::Specification with the given +name+, +version+ and
|
|
|
|
# +platform+. +source+ is ignored.
|
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
def load_spec(name, version, platform, source) # :nodoc:
|
2013-11-10 21:51:40 +04:00
|
|
|
dep = Gem::Dependency.new name, version
|
|
|
|
|
|
|
|
found = @specs.find do |spec|
|
2022-08-09 05:16:07 +03:00
|
|
|
dep.matches_spec?(spec) && spec.platform == platform
|
2013-11-10 21:51:40 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
tuple = Gem::NameTuple.new found.name, found.version, found.platform
|
|
|
|
|
|
|
|
found.source.fetch_spec tuple
|
|
|
|
end
|
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
def pretty_print(q) # :nodoc:
|
2013-12-01 03:27:52 +04:00
|
|
|
q.group 2, "[LockSet", "]" do
|
|
|
|
q.breakable
|
|
|
|
q.text "source:"
|
|
|
|
|
|
|
|
q.breakable
|
|
|
|
q.pp @source
|
|
|
|
|
|
|
|
q.breakable
|
|
|
|
q.text "specs:"
|
|
|
|
|
|
|
|
q.breakable
|
2023-03-16 06:57:49 +03:00
|
|
|
q.pp @specs.map(&:full_name)
|
2013-12-01 03:27:52 +04:00
|
|
|
end
|
|
|
|
end
|
2013-11-10 21:51:40 +04:00
|
|
|
end
|