문제

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.

도움이 되었습니까?

해결책

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

다른 팁

You can use :group option in bundler.

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top