2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-09 16:10:14 -06:00
|
|
|
module PluginGem
|
2017-07-27 20:20:09 -05:00
|
|
|
def self.load(path, name, version, opts = nil)
|
2017-01-09 16:10:14 -06:00
|
|
|
opts ||= {}
|
|
|
|
|
|
|
|
gems_path = File.dirname(path) + "/gems/#{RUBY_VERSION}"
|
2021-04-16 03:21:39 -05:00
|
|
|
|
2017-01-09 16:10:14 -06:00
|
|
|
spec_path = gems_path + "/specifications"
|
2021-04-16 03:21:39 -05:00
|
|
|
|
2023-01-09 06:10:19 -06:00
|
|
|
spec_file = spec_path + "/#{name}-#{version}"
|
2020-08-30 21:36:04 -05:00
|
|
|
spec_file += "-#{opts[:platform]}" if opts[:platform]
|
|
|
|
spec_file += ".gemspec"
|
2021-04-16 03:21:39 -05:00
|
|
|
|
2022-01-05 11:45:08 -06:00
|
|
|
unless File.exist? spec_file
|
2023-01-09 06:10:19 -06:00
|
|
|
command =
|
|
|
|
"gem install #{name} -v #{version} -i #{gems_path} --no-document --ignore-dependencies --no-user-install"
|
2021-04-16 03:21:39 -05:00
|
|
|
command += " --source #{opts[:source]}" if opts[:source]
|
2017-01-09 16:10:14 -06:00
|
|
|
puts command
|
2022-03-06 23:20:43 -06:00
|
|
|
|
2023-01-09 06:10:19 -06:00
|
|
|
Bundler.with_unbundled_env { puts `#{command}` }
|
2017-01-09 16:10:14 -06:00
|
|
|
end
|
2021-04-16 03:21:39 -05:00
|
|
|
|
2022-01-05 11:45:08 -06:00
|
|
|
if File.exist? spec_file
|
2021-04-16 03:21:39 -05:00
|
|
|
Gem.path << gems_path
|
|
|
|
Gem::Specification.load(spec_file).activate
|
|
|
|
|
2023-01-09 06:10:19 -06:00
|
|
|
require opts[:require_name] ? opts[:require_name] : name unless opts[:require] == false
|
2017-01-09 16:10:14 -06:00
|
|
|
else
|
|
|
|
puts "You are specifying the gem #{name} in #{path}, however it does not exist!"
|
2017-08-02 13:00:18 -05:00
|
|
|
puts "Looked for: #{spec_file}"
|
2017-01-09 16:10:14 -06:00
|
|
|
exit(-1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|