Skip to content

Instantly share code, notes, and snippets.

@alloy
Last active March 23, 2016 10:36
Show Gist options
  • Save alloy/f0292ff380647028e9b1 to your computer and use it in GitHub Desktop.
Save alloy/f0292ff380647028e9b1 to your computer and use it in GitHub Desktop.
A Rakefile that standardises program env installation and guides the user, as opposed to crashing with Ruby exceptions such as `LoadError`. The only case where this will *never* work reliably is if you use the `rubygems-bundler` (NOEXEC) plugin, which introduces chicken-and-egg problems.
# Do *not* load any libs here that are *not* part of Ruby’s standard-lib. Ever.
desc "Install all dependencies"
task :bootstrap do
if system('which bundle')
sh "bundle install"
sh "git submodule update --init"
# etc
else
$stderr.puts "\033[0;31m[!] Please install the bundler gem manually: $ [sudo] gem install bundler\e[0m"
exit 1
end
end
begin
# Whatever lib you need to load that is *not* part of Ruby’s standard-lib,
# this includes Bundler.
require 'bundler/gem_tasks'
require 'bundler/setup'
task :something_that_depends_on_the_gem_bundle do
# etc
end
rescue LoadError
$stderr.puts "\033[0;33m[!] Disabling rake tasks because the environment couldn’t be loaded. Be sure to run `rake bootstrap` first.\e[0m"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment