Can a vendor associate a gem setting with a specific operating system?

I am developing Rails 3.1 and using the default uglifier resource. This stone is dependent on execjs, which requires JavaScript runtime. I am developing on Mac OSX, so I have never had a problem with this. Another developer uses Linux, which by default does not have a JavaScript runtime. Therefore, using therubyracer, Ruby's built-in JavaScript runtime works very well, but I would like Bundler to install it only if the system is Linux. Can I specify this in the Gemfile, so it will only be installed on Linux, not Mac?

+4
source share
2 answers

You can do;

gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~ /darwin/i 

replacing the gem and platform with the appropriate ones in your case.

+6
source

The problem with this approach is that if OS X updates Gemfile.lock, the pearl will be turned on. This becomes problematic if another developer updates any gem in the gemfile since the bundler will not include the gem when it calculates the dependencies.

My approach to solving this type of problem was to manually install the gem that I want, and then require both:

 begin require 'os-x-gem' rescue LoadError end begin require 'linux-gem' rescue LoadError end 
+3
source

All Articles