Console or code, … it doesn’t matter.
The Ruby API subcategory has numerous topic threads on gems under SketchUp …
IF (somehow) you copied a gem to the cache, then the Gem installer is supposed to use that instead of trying to download it from the gem server.
Gem::install("mygem")
The “somehow” would need to use FileUtils
to copy the gem file to the cache folder.
(You might also need to provide a .gemspec
file in the “specifications” folder, ie do whatever is usually done when the gem is downloaded from the gem server.)
GEM_CACHE = File.join( ENV['GEM_HOME'], 'cache' )
GEM_SPECS = File.join( ENV['GEM_HOME'], 'specifications' )
When SketchUp loads it adds the GEM_HOME
and GEM_PATH
variables to it’s copy of the environment.
IF the gem is installed into a sub-folder of SketchUp’s “gems” folder, then rubygems modification of Kernel.require
is supposed to find and load it.
GEMS = File.join( ENV['GEM_HOME'], 'gems' )
from Thomas Thomassen on the SketchUp Development team …
I’m not sure if you are able to patch it, the gems system inside a desktop application is a tricky thing.
Note that the gem system isn’t something we’re supporting. There are number of issues with using it in SU.
We’re not able to apply patches to RubyGems for older SU versions. So whenever they make changes that require an update to RubyGems we’re stuck.
We’ve been struggling with OpenSSL issues over the years. Certificates getting out of date eventually, which suffer the same problem with RubyGems in that we cannot provide a patch. There’s also been bugs in Ruby that’s caused issues.
When OpenSSL have worked, in the current versions on Windows it can cause SU to hang/freeze for a very long time (many minutes). (This should be fixed in newer OpenSSL versions, but for that we’ll need to upgrade Ruby inside of SU)
If using gems for an extension you plan to publish, then you’d risk clashing with other extensions trying to use a different version of the gem.
Some gems require compilation, which under Windows require DevKit. This isn’t available on users machines. Nor is DevKit able to detect SketchUp’s Ruby.
Our recommendation if you want to use gems for your extension development is:
Use standalone Ruby (matching the versions for your target SketchUp) and install the gem there. Then you can copy the gem to your extension.
Make sure to wrap the gem into your own namespace so you don’t clash with other extensions. (If you only use it for your own development then you don’t need to do that step.)
2 Likes