Last active
March 23, 2016 10:36
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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