2014-04-01 34 views
0

我正在写一个取决于我创建的另一个宝石的宝石。如何要求自定义宝石

在我的主机的宝石,我需要我的宝石作为这样的依赖性:

$:.push File.expand_path('../lib', __FILE__) 

Gem::Specification.new do |s| 
    s.require_path = "lib" 
    s.files = Dir["lib/**/*"] 
    s.test_files = Dir["spec/**/*"] 

    s.add_dependency "my_other_gem" 
end 

我的Gemfile看起来是这样的:

source "http://rubygems.org" 

gem 'my_other_gem' path: '../my_other_gem', require: 'my_other_gem' 

gemspec 

和主机宝石里面,我已经有需要my_other_gem类:

require 'my_other_gem'

在my_other_gem,我nside lib/my_other_gem.rb,我有两个更多的需求类。所以它看起来像这样:

require 'my_other_gem/foo' 
require 'my_other_gem/bar' 

当我旋转起来IRB在主机应用程序和运行require 'my_other_gem',我得到这个错误

LoadError: cannot load such file -- my_other_gem

当我效力于my_other_gem目录和我旋起IRB,同样的require 'my_other_gem'命令不会出错。一切正常运行。但出于某种原因,当我在我的主机宝石中时,我不能要求my_other_gem。

我错过了什么步骤?

+0

您的主机应用程序中的“bundle install”的输出是什么?它是否正确地找到了my_other_gem? – ouranos

+0

此外,您可能在Gemfile上有错字,它应该是'gem'my_other_gem'路径:'../my_other_gem',要求:'my_other_gem'' – ouranos

+0

感谢您对错字的评论。我在帖子中添加了缺少的冒号。 –

回答

1

你如何开始irb?您需要在bundle exec的捆绑器上下文中运行它。

我刚刚试过,如果我只是运行irb,我得到了同样的错误。 但是,如果我运行bundle exec irb,它的工作原理。

+0

是的。而已。我只是马虎。应该使用bundle exec来运行它。谢谢你的帮助! –