I wanted to use bundler inside gem I wrote. I had Gemfile and in my_gem_file.rb I have
require 'rubygems'
require 'bundler'
Bundler.setup
Bundler.require(:default)
But when I build and install my gem I get exception Bundler::GemfileNotFound: Could not locate Gemfile. Is there any solution for using bundler inside gems?
Since your gem has specified its dependencies in its .gemspec you can assume that they will be available at runtime. Don't involve Bundler.
You can, however, still make use of Bundler for the development of your gem. If you use this Gemfile:
Bundler will look in your .gemspec to determine which gems to install when you run bundle install. You can read more about that here: http://jeffkreeftmeijer.com/2010/bundler-because-your-gems-depend-on-gems-too/
Bundler is not suitable for managment depending gems in gem source. Inside a gem, just require the libraries that you need.
I disagree, Bundler is great for gem development. It helps make it easier to get started and collaborate. And keep the gemspec cleaner?
I'd eliminate the dev dependencies
of course keep the
s.add_dependency("i18n", ["~>0.4.1"])
and others that your gem depends on.You might end up with a Gemfile (as Theo shows), like this
Nice and clean, easy to read. Hope this helps.