Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rubygems: How do I add platform-specific dependency?

Tags:

ruby

rubygems

I've a ruby gem that has different dependencies for each OS. I have to explicitly write all of them down:

On Mac OS X:

gem install livereload 

on Linux:

gem install rb-inotify livereload 

on Windows:

gem install eventmachine-win32 win32-changenotify win32-event livereload 

Can I tweak a gemspec a bit so installation instructions would look like plain gem install livereload for every OS?

like image 473
NVI Avatar asked Jan 04 '11 17:01

NVI


People also ask

Where are RubyGems stored?

When you use the --user-install option, RubyGems will install the gems to a directory inside your home directory, something like ~/. gem/ruby/1.9. 1 . The commands provided by the gems you installed will end up in ~/.

What is a gem Gemfile?

A Gemfile is a file that is created to describe the gem dependencies required to run a Ruby program. A Gemfile should always be placed in the root of the project directory.


1 Answers

The proper way to do this is outlined here. Since the gemspec is evaluated at package time, you need to do it in a native extension. Don't worry, it's not that scary since its still just Ruby code (not compiling C or anything).

We are currently using this approach for some client tools for OpenShift (source). Then in your gemspec/Rakefile, instead of adding dependencies, you would add an extension. Note that the file needs to be named ext/mkrf_conf.rb for this to work.

like image 128
Fotios Avatar answered Sep 26 '22 00:09

Fotios