2013-04-28 22 views
2

當我把我所有寶石中的Gemfile我可以只使用 如何處理與Bundler + Gems的Std-Lib依賴關係?

require 'bundler' 
Bundler.require :default 

加載所有的寶石。現在我想使用Ruby的Std-Lib中的模塊。當然,我可以做

require 'fileutils' 
require 'json' 
[etc.] 

但大多數這些模塊由所需的寶石都已經加載。所以如果我不需要它們,我不會收到錯誤。但是如果我去掉寶石,這很容易改變。

有沒有一種很好的方式來處理這些依賴關係(除了測試)?

+1

明確要求它們。不要依靠你的寶石來爲你做我。 – Linuxios 2013-04-28 20:35:43

+0

好的,但我怎麼知道哪些需要?我必須查找所有模塊嗎?例如:'File'在Core中,不需要,但'FileUtils'在StdLib中並且必須被需要。 – xato 2013-04-28 20:44:32

+0

這並不難。只要看看它。 – Linuxios 2013-04-28 20:45:10

回答

1

好像沒有比找出所有需要的模塊手動並需要手動更好的方法。

我用這個黑客找到需要被需要的模塊列表:

find -name *.rb |xargs cat |egrep -o ' [A-Z][a-zA-Z]*(\.|::)' |tr -dc A-Za-z\\n |sort |uniq |xargs [email protected] -n1 egrep -o '(module|class) @' -r /usr/lib/ruby/1.9.1/* |cut -d':' -f2 |sort |uniq 

它並不完美,但應包括大多數情況。