Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional gem dependencies

Is it possible to conditionally set a dependency on a gem at install time? Here's my situation which will hopefully clarify the question.

There is a gem I maintain that depends on the json gem. However, I frequently use jruby which has a port of the json gem that's called json-jruby. To work around this I have to build two separate gems for each dependency. I'd like to build one gem that either says it depends on json OR json-jruby, or it checks at install time and uses the right dependency.

Anyone have a good solution to this?

like image 520
jshen Avatar asked Jan 27 '09 17:01

jshen


2 Answers

Hmm,

I believe one can code multiple dependencies because I've noticed gems which seemed to do this. But I would you advise against doing this. No matter how simple the code you are inserting here is, when you consider that the user will be loading one gem which depends on another which depends on another, even a small glitch in the logic of one piece of code or another can make the whole dependency train a nightmare.

So, I'd leave your kludge as-is. Further, I'd suggest you have a tarball that users can download as well. I've had to manually extract the code inside of gems whose configuration code wouldn't let me install them.

like image 126
Joe Soul-bringer Avatar answered Oct 16 '22 09:10

Joe Soul-bringer


checkout a somewhat tutorial here: https://github.com/rdp/ruby_tutorials_core/wiki/gem (https://en.wikibooks.org/wiki/Ruby_Programming/RubyGems)

it shows how to install different versions of dependencies depending on what version of ruby the installee is using.

(short answer--it ain't as easy as it should be)

like image 3
rogerdpack Avatar answered Oct 16 '22 11:10

rogerdpack