2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2013-12-07 20:22:39 -05:00
|
|
|
##
|
|
|
|
# The LockSpecification comes from a lockfile (Gem::RequestSet::Lockfile).
|
|
|
|
#
|
|
|
|
# A LockSpecification's dependency information is pre-filled from the
|
|
|
|
# lockfile.
|
|
|
|
|
|
|
|
class Gem::Resolver::LockSpecification < Gem::Resolver::Specification
|
2016-02-01 07:43:26 -05:00
|
|
|
attr_reader :sources
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def initialize(set, name, version, sources, platform)
|
2013-12-07 20:22:39 -05:00
|
|
|
super()
|
|
|
|
|
|
|
|
@name = name
|
|
|
|
@platform = platform
|
|
|
|
@set = set
|
2016-02-01 07:43:26 -05:00
|
|
|
@source = sources.first
|
|
|
|
@sources = sources
|
2013-12-07 20:22:39 -05:00
|
|
|
@version = version
|
|
|
|
|
|
|
|
@dependencies = []
|
|
|
|
@spec = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# This is a null install as a locked specification is considered installed.
|
|
|
|
# +options+ are ignored.
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def install(options = {})
|
2013-12-07 20:22:39 -05:00
|
|
|
destination = options[:install_dir] || Gem.dir
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
if File.exist? File.join(destination, "specifications", spec.spec_name)
|
2013-12-07 20:22:39 -05:00
|
|
|
yield nil
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Adds +dependency+ from the lockfile to this specification
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def add_dependency(dependency) # :nodoc:
|
2013-12-07 20:22:39 -05:00
|
|
|
@dependencies << dependency
|
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def pretty_print(q) # :nodoc:
|
2014-09-13 23:30:02 -04:00
|
|
|
q.group 2, "[LockSpecification", "]" do
|
|
|
|
q.breakable
|
|
|
|
q.text "name: #{@name}"
|
|
|
|
|
|
|
|
q.breakable
|
|
|
|
q.text "version: #{@version}"
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
unless @platform == Gem::Platform::RUBY
|
2014-09-13 23:30:02 -04:00
|
|
|
q.breakable
|
|
|
|
q.text "platform: #{@platform}"
|
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
unless @dependencies.empty?
|
2014-09-13 23:30:02 -04:00
|
|
|
q.breakable
|
|
|
|
q.text "dependencies:"
|
|
|
|
q.breakable
|
|
|
|
q.pp @dependencies
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-12-07 20:22:39 -05:00
|
|
|
##
|
|
|
|
# A specification constructed from the lockfile is returned
|
|
|
|
|
|
|
|
def spec
|
2019-02-14 07:59:03 -05:00
|
|
|
@spec ||= Gem::Specification.find do |spec|
|
2022-08-08 22:16:07 -04:00
|
|
|
spec.name == @name && spec.version == @version
|
2019-02-14 07:59:03 -05:00
|
|
|
end
|
2014-09-13 23:30:02 -04:00
|
|
|
|
2013-12-07 20:22:39 -05:00
|
|
|
@spec ||= Gem::Specification.new do |s|
|
|
|
|
s.name = @name
|
|
|
|
s.version = @version
|
|
|
|
s.platform = @platform
|
|
|
|
|
|
|
|
s.dependencies.concat @dependencies
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|