Using bundler inside my gem

空扰寡人 提交于 2020-01-01 19:34:09

问题


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?


回答1:


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:

source :rubygems
gemspec

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/




回答2:


Bundler is not suitable for managment depending gems in gem source. Inside a gem, just require the libraries that you need.




回答3:


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

Gem::Specification.new do |s|
  s.add_development_dependency("mocha", ["~>0.9.8"])

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

source :rubygems
gemspec

group :test do
  gem 'rails', '3.0.0'
  gem 'mocha'
  gem 'rspec-rails', "~>2.0.1"
end

Nice and clean, easy to read. Hope this helps.



来源:https://stackoverflow.com/questions/4127692/using-bundler-inside-my-gem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!