简体   繁体   English

如何在Rails项目的rake任务中使用外部(对于bundler)util gem

[英]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.

相关问题 如何使用 Rails clockwork gem 运行 rake 任务? - How do I use Rails clockwork gem to run rake tasks? 如何在铁轨外的耙子任务中使用耙子? - How to use rake with rake tasks outside rails? Rails:如何显式初始化与gem捆绑在一起的rake任务? - Rails: How to explicitly initialize rake tasks “bundled” with a gem? 在Bundler的Rails项目中正确使用宝石中的Rack中间件的正确方法 - Proper way to use a Rack middleware from a gem in a Rails project with Bundler 为什么这个gem没有将rake任务添加到Rails应用程序? - Why is this gem not adding rake tasks to a Rails app? 如何在带有bundler的项目中使用rails的fork中的分支 - How to use a branch in a fork of rails in a project with bundler Bundler使用every和rake任务找不到与宝石“ bundler”兼容的版本 - Bundler could not find compatible versions for gem “bundler” using whenever and rake tasks 了解JRuby,Rails,Gem,Rake和Bundler之间的联系 - Understanding the connection between JRuby, Rails, Gem, Rake, and Bundler 如何使用每当宝石测试抽佣任务? - How to test rake tasks with Whenever Gem? 如何使用每当宝石,在红宝石的亚马逊AWS服务器上执行耙任务? - how to execute rake tasks using whenever gem, in amazon aws server in ruby on rails?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM