How would you set dynamically determined dependencies with or without bundler?

Hi!

I have developing a gem where some of it’s dependencies are not
in .gemspec since they can be different depending of the value of
environment variable, class variable or just depending of the OS in
use. In short, these dependencies expose the same API, but can be
switched during runtime before actually loading the gem itself. The
gem then does something in the lines of:
require “rubygems”
gem “dependency”, “version”
require “dependency”

depending of some criteria as written above. Now when using Bundler
with it’s Bundler.setup invocation, what should be in Gemfile so it
would work the same on every configuration without having to have
modified Gemfile and Gemfile.lock on each different machine.

Can i have different “gem” lines in Gemfile on different machines and
commit it actually into VCS without having to modify it on each and
every machine separately?

Something in the Gemfile like this would work perfectly?
if RUBY_PLATFORM =~ /mswin|msys|mingw32/
gem “dep1”
else
gem “dep2”
end

In that case “dep1” and “dep2” would end up in Gemfile.lock - is it
okay, even if dep1 is not installable on unix platform?

Jarmo P.

After playing around a little i found this solution to be the one i
needed - in Gemfile:

platforms :mswin, :mingw do
gem “win-specific-gem1”
gem “win-specific-gem2”
end

gem “gem3” # works on all platforms

Now in my gem i just do require “win-specific-gemX” if the OS is win
and on other’s require “gem3”. If there’s any better solution then let
me know of course :slight_smile:

Jarmo P.

IT does really matter - http://www.itreallymatters.net

unsubscribe

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs