2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-09 17:10:14 -05:00
|
|
|
module PluginGem
|
|
|
|
def self.load(path, name, version, opts = nil)
|
|
|
|
opts ||= {}
|
|
|
|
|
|
|
|
gems_path = File.dirname(path) + "/gems/#{RUBY_VERSION}"
|
2021-04-16 04:21:39 -04:00
|
|
|
|
2017-01-09 17:10:14 -05:00
|
|
|
spec_path = gems_path + "/specifications"
|
2021-04-16 04:21:39 -04:00
|
|
|
|
|
|
|
spec_file = spec_path + "/#{name}-#{version}"
|
|
|
|
|
2024-05-27 06:27:13 -04:00
|
|
|
if platform_variants(spec_file).find(&File.method(:exist?)).blank?
|
2021-04-16 04:21:39 -04:00
|
|
|
command =
|
|
|
|
"gem install #{name} -v #{version} -i #{gems_path} --no-document --ignore-dependencies --no-user-install"
|
|
|
|
command += " --source #{opts[:source]}" if opts[:source]
|
2017-01-09 17:10:14 -05:00
|
|
|
puts command
|
2022-03-07 00:20:43 -05:00
|
|
|
|
|
|
|
Bundler.with_unbundled_env { puts `#{command}` }
|
2017-01-09 17:10:14 -05:00
|
|
|
end
|
2021-04-16 04:21:39 -04:00
|
|
|
|
2023-06-26 14:11:35 -04:00
|
|
|
spec_file_variant = platform_variants(spec_file).find(&File.method(:exist?))
|
|
|
|
if spec_file_variant.present?
|
2021-04-16 04:21:39 -04:00
|
|
|
Gem.path << gems_path
|
2023-06-26 14:11:35 -04:00
|
|
|
Gem::Specification.load(spec_file_variant).activate
|
2021-04-16 04:21:39 -04:00
|
|
|
|
2017-01-09 17:10:14 -05:00
|
|
|
require opts[:require_name] ? opts[:require_name] : name unless opts[:require] == false
|
|
|
|
else
|
|
|
|
puts "You are specifying the gem #{name} in #{path}, however it does not exist!"
|
2023-06-26 14:11:35 -04:00
|
|
|
puts "Looked for: \n- #{platform_variants(spec_file).join("\n- ")}"
|
2017-01-09 17:10:14 -05:00
|
|
|
exit(-1)
|
|
|
|
end
|
|
|
|
end
|
2023-06-26 14:11:35 -04:00
|
|
|
|
|
|
|
def self.platform_variants(spec_file)
|
|
|
|
platform_less = "#{spec_file}.gemspec"
|
|
|
|
|
|
|
|
platform_full = "#{spec_file}-#{RUBY_PLATFORM}.gemspec"
|
|
|
|
|
|
|
|
platform_version_less =
|
|
|
|
"#{spec_file}-#{Gem::Platform.local.cpu}-#{Gem::Platform.local.os}.gemspec"
|
|
|
|
|
|
|
|
[platform_less, platform_full, platform_version_less]
|
|
|
|
end
|
2017-01-09 17:10:14 -05:00
|
|
|
end
|