Programatically identifying gems, and shipping them between environment

My goal is this: I have two computers and a jruby script which has a
couple
of “require” statements in it. The script runs fine on computer one. My
goal is to get it to run on computer two such that I actually ship the
script and the gems that are required in the script (imagine computer
two
is a fresh install of jruby with no gems).

What is the easiest way to do this?

What I am thinking is to run the script in the first environment, see
what
gems are in the first environment, ship them over, and voila. First off,
is
this reasonable?

Second: is there a way to see what gems are loaded in the current ruby
environment?
Third: given those gems, I believe I can do the following to get the
spec:
Gem::Specification.find_by_name(gem), but what files do I need to ship
over? If I tar and zip everything in .gem_dir, how can I make that
available on the second computer?

Does this make sense? Thanks for the help!
Jon

Are you familiar with Bundler (http://gembundler.com/)? See also bundle
package Gem Bundler – Manage your Ruby gems

I think I can reach my goal without using bundler, and ideally I don’t
want
users to have to setup a separate file unless they really have to.

I’ve figured out how to get the loaded gems and where they are
installed,
so now it’s just a matter of getting them on the right path in the other
environment.

2012/9/27 Richie V. [email protected]

When I start a new JRuby project I create a directory for it and extract
JRuby into it. I create a short shell script that I can double-click to
open a terminal at that directory and which also adds the JRuby /bin
directory to the Path. Then when I do gem install xxx the gem is
automatically put into the JRuby in that directory. After I have
completed my program I can then copy the whole directory to any other
computer and it works the same (assuming the other computer has the
JVM). This works with JRuby using java stuff like Swing and Miglayout
also, provided the jars are also in the project directory.

On 27.09.2012 20:09, Jonathan C. wrote:

My goal is this: I have two computers and a jruby script which has a
couple of “require” statements in it. The script runs fine on
computer
one. My goal is to get it to run on computer two such that I actually
ship the script and the gems that are required in the script (imagine
computer two is a fresh install of jruby with no gems).

What is the easiest way to do this?

Not sure what the easiest way is (I’d look at Bundler; it has some
means
to package up all dependency gems into a folder).

Second: is there a way to see what gems are loaded in the current
ruby
environment?

This might get you started:

 Gem.loaded_specs.map{|name, spec| puts "#{name} at

#{spec.full_gem_path}"}

Should list all currently loaded gems.


Patrick M.

Patrick -

Thanks, that is very cool, I didn’t know you could do that.

For this kind of output I like to use the C language style formatted
output, e.g.:

1.9.3p125 :014 > Gem.loaded_specs.map{|name, spec| puts (“%-25s at:
%s” % [name, spec.full_gem_path]) }
life_game_viewer at:
/Users/keithb/.rvm/gems/ruby-1.9.3-p125/gems/life_game_viewer-0.9.2
rspec-core at:
/Users/keithb/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-2.11.0
diff-lcs at:
/Users/keithb/.rvm/gems/ruby-1.9.3-p125/gems/diff-lcs-1.1.3
rspec-expectations at:
/Users/keithb/.rvm/gems/ruby-1.9.3-p125/gems/rspec-expectations-2.11.1
rspec-mocks at:
/Users/keithb/.rvm/gems/ruby-1.9.3-p125/gems/rspec-mocks-2.11.0
rspec at:
/Users/keithb/.rvm/gems/ruby-1.9.3-p125/gems/rspec-2.11.0

That’s not relevant to your point, but I like to mention it because lots
of folks don’t know about it, and it can be very useful.

  • Keith

Keith R. Bennett

Very useful, Patrick.

2012/10/1 Keith B. [email protected]