mirror of
https://github.com/discourse/discourse.git
synced 2024-12-05 10:36:30 +08:00
c5fd8c42db
* File.exists? is deprecated and removed in Ruby 3.2 in favor of File.exist? * Dir.exists? is deprecated and removed in Ruby 3.2 in favor of Dir.exist?
36 lines
1019 B
Ruby
36 lines
1019 B
Ruby
# frozen_string_literal: true
|
|
|
|
module PluginGem
|
|
def self.load(path, name, version, opts = nil)
|
|
opts ||= {}
|
|
|
|
gems_path = File.dirname(path) + "/gems/#{RUBY_VERSION}"
|
|
|
|
spec_path = gems_path + "/specifications"
|
|
|
|
spec_file = spec_path + "/#{name}-#{version}"
|
|
spec_file += "-#{opts[:platform]}" if opts[:platform]
|
|
spec_file += ".gemspec"
|
|
|
|
unless File.exist? spec_file
|
|
command = "gem install #{name} -v #{version} -i #{gems_path} --no-document --ignore-dependencies --no-user-install"
|
|
command += " --source #{opts[:source]}" if opts[:source]
|
|
puts command
|
|
puts `#{command}`
|
|
end
|
|
|
|
if File.exist? spec_file
|
|
Gem.path << gems_path
|
|
Gem::Specification.load(spec_file).activate
|
|
|
|
unless opts[:require] == false
|
|
require opts[:require_name] ? opts[:require_name] : name
|
|
end
|
|
else
|
|
puts "You are specifying the gem #{name} in #{path}, however it does not exist!"
|
|
puts "Looked for: #{spec_file}"
|
|
exit(-1)
|
|
end
|
|
end
|
|
end
|