2014-04-01 35 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來運行它。謝謝你的幫助! –