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

J

Jarmo Pertman

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 Pertman
 
J

Jarmo Pertman

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 :)

Jarmo Pertman
 
K

Kane Williams

unsubscribe
Date: Sat=2C 18 Jun 2011 18:45:32 +0900
From: (e-mail address removed)
Subject: Re: how would you set dynamically determined dependencies with o= r without bundler?
To: (e-mail address removed)
=20
After playing around a little i found this solution to be the one i
needed - in Gemfile:
=20
platforms :mswin=2C :mingw do
gem "win-specific-gem1"
gem "win-specific-gem2"
end
=20
gem "gem3" # works on all platforms
=20
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 :)
=20
Jarmo Pertman
-----
IT does really matter - http://www.itreallymatters.net
=20

=20
=20
=
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top