Question

I am writing a gem that can be used with both Sinatra and Rails, however, the gem dependencies are different based on which framework the developer is using the gem on.

If it's a rails app, we need 'sass-rails' and 'coffee-rails' If it's a sinatra app, we need 'sass' and 'coffee-script'

Ideally bundler would just install the necessary gems based on which framework this gem is being loaded into, but I can't seem to figure out how to conditionally specify dependencies.

Any suggestions would be much appreciated.

Was it helpful?

Solution

I would suggest you not to do that. It would be hackish and unreliable.

What you can do however is divide and conquer! Build a generic version of your gem that is framework agnostic and only handles the logic, let's call it yourgem-core, then you can build two other gems based on that first one, called yourgem-rails and yourgems-sinatra.

It's much better, only logic and logic test in yourgem-core, only rails integration tests in yourgem-rails, only sinatra integration tests in yourgem-sinatra

OTHER TIPS

You can use :group option in bundler.

Reference: http://bundler.io/v1.5/groups.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top