Module: GuessRakeTask
- Included in:
- Rake::TaskManager
- Defined in:
- lib/guessmethod/rake.rb
Overview
GuessRakeTask is pretty much a bad idea gone worse. When included into Rake::TaskManager, it overtakes TaskManager’s [] method and tries to guess when the task lookup fails. Use via the grake command, or by adding “require ‘guessmethod/rake’” to the top of your Rakefiles.
Class Method Summary collapse
Instance Method Summary collapse
-
#guess_brackets(task_name, scopes = nil) ⇒ Object
GuessRakeTask’s magic.
Class Method Details
.included(base) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/guessmethod/rake.rb', line 12 def self.included(base) base.class_eval do alias_method :unguessed_brackets, :[] alias_method :[], :guess_brackets end end |
Instance Method Details
#guess_brackets(task_name, scopes = nil) ⇒ Object
GuessRakeTask’s magic. Go for Rake::TaskManager’s [] lookup first, then guess at it if it fails.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/guessmethod/rake.rb', line 21 def guess_brackets(task_name, scopes=nil) begin unguessed_brackets(task_name, scopes) rescue RuntimeError => e possible_tasks = GuessMethod::GuessMethodGuesser.find_closest(@tasks.keys, task_name) case possible_tasks.size when 1 task_to_call = possible_tasks.first $stderr.puts GuessMethod::GuessMethodOutputter.replacing_rake_task(task_name, task_to_call) unguessed_brackets(task_to_call, scopes) when 0 $stderr.puts GuessMethod::GuessMethodOutputter.no_rake_task_in_threshold(task_name) raise e else $stderr.puts GuessMethod::GuessMethodOutputter.ambigous_rake_task(task_name, possible_tasks) raise e end end end |