I’m experimenting with Ruby and SU, and came across an issue with gem list
on Windows. On Windows, the gem directory is in a user folder that the user has full rights to. The SU application is installed in a normal app folder where the user may not have full rights. On windows, this a normal practice.
I just opened an issue in rubygems/rubygems
to fix the issue, but I’m not sure how OSX sets up the folders. Is the gem folder in a separate folder from the SU application?
If I’m not being clear, the following code should output the gem environment
and gem list
commands to the Ruby Console. What I’m interested in is the OSX SU installation folder and the INSTALLATION DIRECTORY
listed in Gem environment
.
# frozen_string_literal: true
# load '<path to file>'
# Runs gem environment and gem list, outputs to Ruby Console, handles IO routing...
SKETCHUP_CONSOLE.clear if defined? SKETCHUP_CONSOLE
require 'stringio'
require 'rubygems/commands/environment_command'
require 'rubygems/commands/list_command'
# create streamUI with io
sio_in, sio_out, sio_err = StringIO.new, StringIO.new, StringIO.new
strm_io = Gem::StreamUI.new(sio_in, sio_out, sio_err, false)
# create environment command & attach io
cmd = Gem::Commands::EnvironmentCommand.new
cmd.ui = strm_io
cmd.options[:args] = []
# environment execute & get info
cmd.execute
cnsl_out = String.new("#{'-' * 50} Gem Environment\n")
cnsl_out << sio_out.string
sio_out.truncate(0) # Other apps might require sio_err to be flushed
sio_out.rewind
# create list command & attach io
cmd = Gem::Commands::ListCommand.new
cmd.ui = strm_io
# list execute & get info
cmd.execute
cnsl_out << "\n#{'-' * 50} Installed Gems\n"
cnsl_out << sio_out.string
cnsl_out << "#{'-' * 66}"
puts cnsl_out
# clean up
cmd = nil
strm_io = nil
sio_in.close ; sio_out.close ; sio_err.close
sio_in, sio_out, sio_err = nil, nil, nil