Reputation: 11900
I can run the following two commands from my bash shell -
bundle check --gemfile=/path/to/some/Gemfile
bundle install --gemfile=/path/to/some/Gemfile
How do I run these from inside a Ruby script without shelling out (e.g. without using ``, system()
, exec()
, etc..)?
Specifically, does Bundler offer some API like Bundler.check()
where I can call this process and receive output on whether it was successful or not?
Thanks!
EDIT I'm aware that bundler/inline
provides a way to specify a gemfile
block within the same file, but the scope of this question is how to run check
and install
on any arbitrary Gemfile
Upvotes: 2
Views: 1223
Reputation: 357
This should do the trick, from within a Ruby Script
require 'bundler'
definition = Bundler.definition
begin
definition.resolve_with_cache!
rescue Bundler::GemNotFound => e
puts "missing dependencies, let's try remotely"
begin
definition.resolve_remotely!
rescue
puts "damn ! could not satisfy dependencies !"
end
end
Upvotes: 1