Created
October 2, 2012 11:24
-
-
Save joakimk/3818301 to your computer and use it in GitHub Desktop.
Try to run no-rails rake tasks first and fallback to rails when none is found.
This file contains hidden or 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
task :fast do | |
puts "This does not load rails" | |
end | |
namespace :spec do | |
task :unit do | |
# See https://github.com/joakimk/fast_unit_tests_example/blob/master/Rakefile for more info. | |
end | |
end |
This file contains hidden or 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
#!/usr/bin/env rake | |
# If the code below fails, uncomment this. There are no known issues now, but we had one. | |
#require File.expand_path('../config/application', __FILE__) | |
#Auctionet::Application.load_tasks | |
#require File.expand_path('../lib/tasks/no_rails', __FILE__) | |
#__END__ | |
# Load all non-rails tasks. | |
path = File.expand_path('../lib/tasks/no_rails', __FILE__) | |
Dir.entries(path).each do |file| | |
next unless file.include?('.rb') | |
require File.join(path, file) | |
end | |
# Try to run no-rails tasks first. Fallback to rails if none is found. | |
module LoadRailsTasks | |
def self.load | |
require File.expand_path('../config/application', __FILE__) | |
App::Application.load_tasks | |
end | |
end | |
Rake.application.instance_eval do | |
module Rake | |
class Task | |
alias :old_lookup_prerequisite :lookup_prerequisite | |
def lookup_prerequisite(prerequisite_name) | |
if prerequisite_name == "environment" && !Rake.application.lookup(prerequisite_name) | |
LoadRailsTasks.load | |
end | |
old_lookup_prerequisite(prerequisite_name) | |
end | |
end | |
end | |
def top_level | |
if running_a_task? && requested_tasks_exist? | |
super | |
else | |
LoadRailsTasks.load | |
super | |
end | |
end | |
def running_a_task? | |
!(options.show_tasks || options.show_prereqs) | |
end | |
def requested_tasks_exist? | |
top_level_tasks.any? { |task| lookup(task) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment