running extern ruby script behind of Gemfile

90 views
Skip to first unread message

Igor Yurchenko

unread,
Sep 1, 2015, 11:18:14 PM9/1/15
to ruby-bundler

I'm trying to integrate backup gem (github.com/backup/backup) at rails project. Backup gem is not recommended for using in Gemfile, so I'm trying to install it by capistrano task. And I make task in lib/rasks/backup.rake path, contained something like:


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. So we decide the using Gemfile is not apropriate in our current case.

I would be very thankful for ideas to solve this problem...


Thanks in advance..

Tim Moore

unread,
Sep 2, 2015, 12:37:04 AM9/2/15
to ruby-b...@googlegroups.com
Igor,

If you want to execute a command outside of the context of your bundle, you need to use `Bundler.with_clean_env`:

namespace :backup do
  desc "Perfom Backup"
  task :perform do
    Bundler.with_clean_env { %x{ backup perform -t beam_bank -c config/Backup/config.rb } }
  end
end
In this case, where you're not actually using the return value from %x, you could also use the `clean_system` helper method:

namespace :backup do
  desc "Perfom Backup"
  task :perform do
    Bundler.clean_system 'backup perform -t beam_bank -c config/Backup/config.rb'
  end
end

There are docs about this at http://bundler.io/v1.10/man/bundle-exec.1.html#Shelling-out

Cheers,
Tim

--
You received this message because you are subscribed to the Google Groups "ruby-bundler" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-bundler...@googlegroups.com.
To post to this group, send email to ruby-b...@googlegroups.com.
Visit this group at http://groups.google.com/group/ruby-bundler.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages