2013-03-16 52 views
10

我一直在嘗試在我的當前應用中包含位於github上的寶石。該寶石有一個耙文件,我想能夠從我的應用程序訪問。但我不斷收到加載錯誤。Ruby Rake從寶石中加載任務

load 'tasks/deploy.rake' 

寶石文件看起來像

# -*- encoding: utf-8 -*- 
require 'rake' 

Gem::Specification.new do |gem| 
    gem.authors  = %w(Hello World) 
    gem.email   = %w([email protected]) 
    gem.description = 'test' 
    gem.summary  = 'test' 
    gem.homepage  = 'https://github.com/..' 
    gem.files   = FileList[ 'lib/**/*.rb', 'tasks/deploy.rake', 'README.md' ].to_a 
    gem.name   = 'test' 
    gem.require_paths = %w(lib) 
    gem.version  = '0.0.1' 
end 

我希望能夠加載./tasks/deploy.rake到我的應用程序,其中包括這顆寶石,我怎麼去上吧?

感謝

回答

21

好吧,我找到了一個解決這個問題,如果有人有興趣:

# Rails.root/Rakefile 

spec = Gem::Specification.find_by_name 'test' 
load "#{spec.gem_dir}/tasks/deploy.rake" 

這就是我需要在我的Rakefile的說!

+1

對我來說,還要在應用程序的rakefile(不是寶石)中放入'require'/rake_tasks'' – msa7 2013-09-24 08:06:27

+0

@SergXIIIth它取決於gem的結構。例如,對於'sitemap_generator',它是'require'sitemap_generator/tasks'',對於'padrino'則'require'padrino-core/cli/rake''等。 – jibiel 2013-12-15 14:16:24