My question boils down to this. How do I get ruby running within an embedded script to recognise where the third-party gem files are located? Read on for more detail.
As far as I can tell, the script fails on the require 'gemname' call for any gems that are not built into ruby itself. Here's my test code in Hazel.
- Code: Select all
cat "$1" >> /Users/DCB/Desktop/Hazel.log
/Users/DCB/.rvm/rubies/ruby-1.9.3-p327/bin/ruby -v >> /Users/DCB/Desktop/Hazel.log
/Users/DCB/.rvm/rubies/ruby-1.9.3-p327/bin/ruby ~/Documents/test.rb "$1" >> /Users/DCB/Desktop/Hazel.log
The first two lines are proving Hazel is neither erroring on the filename, nor is it failing to get the wrong version of ruby. From this I learnt I had to provide the full ruby path. The final line runs a test script.
- Code: Select all
#!/usr/bin/ruby
require 'rubygems'
#require 'plist' # If missing, from commandline run "gem install plist"
require 'optparse'
#require 'logger' # If missing, from commandline run "gem install logger"
#require 'nokogiri'
puts "Test script works"
ARGV.each do |a|
puts a
end
As shown above the script runs without error and correctly outputs the file name from with in the script. Both rubygems and optparse are built-in gems and work fine. If I uncomment any of plist, logger or nokogiri I get a scripting error.
To try and fix this I added the following to the script in order to set the GEM paths but it failed.
- Code: Select all
cat "$1" >> /Users/DCB/Desktop/Hazel.log
/Users/DCB/.rvm/rubies/ruby-1.9.3-p327/bin/ruby -v >> /Users/DCB/Desktop/Hazel.log
export GEM_HOME=/Users/DCB/.rvm/gems/ruby-1.9.3-p327/gems
export GEM_PATH=/Users/DCB/.rvm/gems/ruby-1.9.3-p327/gems
/Users/DCB/.rvm/rubies/ruby-1.9.3-p327/bin/ruby ~/Documents/test.rb "$1" >> /Users/DCB/Desktop/Hazel.log
The same two lines appear in my .bash_profile as well. The embedded script's shell is /bin/bash
How do I get ruby running within an embedded script to recognise where the gem files are located?
Thanks,
-David