mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 02:19:27 +08:00
30990006a9
This reduces chances of errors where consumers of strings mutate inputs and reduces memory usage of the app. Test suite passes now, but there may be some stuff left, so we will run a few sites on a branch prior to merging
31 lines
943 B
Ruby
31 lines
943 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}.gemspec"
|
|
unless File.exists? spec_file
|
|
command = "gem install #{name} -v #{version} -i #{gems_path} --no-document --ignore-dependencies --no-user-install"
|
|
if opts[:source]
|
|
command << " --source #{opts[:source]}"
|
|
end
|
|
puts command
|
|
puts `#{command}`
|
|
end
|
|
if File.exists? spec_file
|
|
spec = Gem::Specification.load spec_file
|
|
spec.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
|