Created
November 30, 2012 10:48
-
-
Save seanlinsley/4175087 to your computer and use it in GitHub Desktop.
Faster rake is better rake
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
# located in lib/tasks/ | |
task default: :help | |
desc "to get you running" | |
task :help do | |
puts "\033[33mFYI: We're not running the usual Rake setup.\033[0m\n" + | |
"To list the Rails rake tasks, run `\033[32mLOAD_RAILS=1 rake -T\033[0m`\n" + | |
"Append the normal command with a \033[31mbang!\033[0m to run those tasks\n" + | |
"... If you'd like to know more, check out the Rakefile" | |
end |
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
# Rakefile inspired by http://rhnh.net/2010/09/07/speeding-up-rails-rake | |
def load_rails_environment | |
require File.expand_path('../config/application', __FILE__) | |
require 'rake' | |
TimeAudit::Application.load_tasks | |
end | |
# By default, do not load the Rails environment. This allows for faster | |
# loading of all the rake files, so that getting the task list, or kicking | |
# off a spec run (which loads the environment by itself anyways) is much quicker. | |
if ENV['LOAD_RAILS'] == '1' | |
load_rails_environment # Bypass the hacks below so everything works as intended. | |
else | |
# If you don't want to use LOAD_RAILS, just end the command with a bang! | |
rule "!" do |t| # so `rake db:migrate!` works just fine | |
load_rails_environment | |
Rake::Task[t.to_s.chomp("!")].invoke | |
end | |
# For posterity, add a bit of documentation that shows up in `rake -T` | |
desc "\033[33mRails tasks aren't loaded\033[0m; check out `rake help`" | |
task :_fyi | |
end | |
# Load all tasks defined in lib/tasks/*.rake | |
Dir[File.expand_path("../lib/tasks/", __FILE__) + '/*.rake'].each do |file| | |
load file | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment