phortx
phortx

Reputation: 919

Bundler: Allow user added gems in an UserGemfile

I'm developing a ruby/rails application which should be highly extensible by adding plugins. A plugin is - obviously - a gem, which follows specific roules and contains library code, a rails engine with assets, routes, controllers, views and whatever. Additionally there wille be some kind of API which allows the plugin developer to register custom entries to abstract concepts of the app like adding cronjobs (theres some kind of cron in the main system), adding commands to the CLI and so on.

There will be some 'builtin' plugins containted in the Gemfile shipped with the app due they're part of the app and always activated. And there will be a pool of community written gems which are optional.

Now I'm searching for a possibility to let the user, who installs the app on his machine, addional gems (containing plugins) to the app.

The simplest (but not best) solution would be to say "Just add the plugin gems you want to the Gemfile before running bundle install)". But if there comes an update of the app, the Gemfile would be potentially conflicting and either be resetted or the user have to resolve those conflicts. That's something I don't want actually.

A nicer way would be to say "Hey, here's a UserGemfile, just add the plugin gems you want to that file and run bundle install". That UserGemfile would be listed in the .gitignore and everything would be nice.

Unfortunately it seems like bundler doesn't support something like that.

Do you have any advice how to tackle that issue?

Upvotes: 0

Views: 45

Answers (1)

juan_julian_reveira
juan_julian_reveira

Reputation: 169

You can do something like this, in, say, import_gems:

puts `cat Gemfile UserGemfile > EffectiveGemfile`
puts `bundle install --gemfile=EffectiveGemfile`

Then, when you run your application, specify the Gemfile:

BUNDLE_GEMFILE=EffectiveGemfile bundle list

Make sure to add EffectiveGemfile and EffectiveGemfile.lock to .gitignore as well.

Upvotes: 1

Related Questions