簡體   English   中英

如何在Rails項目的rake任務中使用外部(對於bundler)util gem

[英]How to use external (for bundler) util gem with rake tasks of rails project

我正在嘗試在Rails項目中集成備份gem(github.com/backup/backup)。 不建議在Gemfile中使用備份gem,因此我嘗試通過capistrano任務安裝它。 我在lib / rasks / backup.rake路徑中執行任務,其中包含以下內容:

namespace :backup do
  desc "Perfom Backup"
  task :perform do
    %x{ backup perform -t beam_bank -c config/Backup/config.rb }
  end
end

但是執行該任務會導致錯誤:

micron-l% rake backup:perform
/home/space/.gem/ruby/2.2.0/gems/bundler-1.10.6/lib/bundler/rubygems_integration.rb:292:in `block in replace_gem': backup is not part of the bundle. Add it to Gemfile. (Gem::LoadError)
    from /home/space/.gem/ruby/2.2.0/bin/backup:22:in `<main>'

在Gemfile中添加“ gem'backup',require:false”會導致一些依賴沖突。 因此,我們認為在當前情況下,使用Gemfile不適當。

我非常感謝解決這個問題的想法...預先感謝..

答案是:

使用捆綁程序幫助程序在干凈的環境中運行腳本。 在這種情況下,可以執行以下操作:

Bundler.clean_system('backup perform -t beam_bank -c config/Backup/config.rb')

關於此問題的文檔參考: http : //bundler.io/v1.10/man/bundle-exec.1.html#Shelling-out

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM