[英]How to use external (for bundler) util gem with rake tasks of rails project
I'm trying to integrate backup gem (github.com/backup/backup) at rails project. 我正在尝试在Rails项目中集成备份gem(github.com/backup/backup)。 Backup gem is not recommended for using in Gemfile, so I'm trying to install it by capistrano task. 不建议在Gemfile中使用备份gem,因此我尝试通过capistrano任务安装它。 And I make task in lib/rasks/backup.rake path, contained something like: 我在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
But executing that task cause error: 但是执行该任务会导致错误:
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>'
Adding "gem 'backup', require: false" to Gemfile cause some dependency conflict. 在Gemfile中添加“ gem'backup',require:false”会导致一些依赖冲突。 So we decide the using Gemfile is not apropriate in our current case. 因此,我们认为在当前情况下,使用Gemfile不适当。
I would be very thankful for ideas to solve this problem... Thanks in advance.. 我非常感谢解决这个问题的想法...预先感谢..
The answer is: 答案是:
Use bundler helper for run script in clean environment. 使用捆绑程序帮助程序在干净的环境中运行脚本。 In this case it can be done something like this: 在这种情况下,可以执行以下操作:
Bundler.clean_system('backup perform -t beam_bank -c config/Backup/config.rb')
The reference to docs on this problem: http://bundler.io/v1.10/man/bundle-exec.1.html#Shelling-out 关于此问题的文档参考: http : //bundler.io/v1.10/man/bundle-exec.1.html#Shelling-out
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.