Reputation: 499
I am creating a Rails plugin (yes, I need a plugin, not a gem).
This plugin has several gem dependencies. My first thought was to list the dependencies in a Gemfile at the root of the plugin directory.
From the install.rb, I did the following :
`bundle install`
And then from init.rb, I did the following :
require 'rubygems'
require 'bundler/setup'
Bundler.require
But bundler is not definitely these dependencies.
I do not want to have to list the gem dependencies in the root Gemfile.
Is there any way to include these gems within the plugin and just have it work without the end user having to alter their own Gemfile? I'm not opposed to ditching Bundler all together if there were some other mechanism for pulling in gem dependencies for Rails plugins?
Upvotes: 1
Views: 161
Reputation: 14189
It doesn't require your gems because the gem environment (gem set, whatever) is already set up by the app.
It's not possible to isolate the plugin's gem env from the app's gem env for the simple reason that the plugin runs inside the app.
Thus, the plugin runs in the app's gem env.
If the app's gem env is managed by Bundler, then your dependencies must be defined in the app's Gemfile. Otherwise they won't be available inside the gem env isolated by Bundler, no matter what you would require from inside your plugin.
This is one of the reasons why it's more practical to release plugins as gems.
Upvotes: 1