Skip to content

Instantly share code, notes, and snippets.

@joakimk
Created October 2, 2012 11:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joakimk/3818301 to your computer and use it in GitHub Desktop.
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.
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
#!/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