Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support did_you_mean >= v1.2.0 which has a breaking change on formatters #262

Merged
merged 1 commit into from
Mar 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions lib/rake/task_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,20 @@ def [](task_name, scopes=nil)

def generate_message_for_undefined_task(task_name)
message = "Don't know how to build task '#{task_name}' (see --tasks)"
message + generate_did_you_mean_suggestions(task_name)
end

suggestion_message = \
if defined?(::DidYouMean::SpellChecker) && defined?(::DidYouMean::Formatter)
suggestions = ::DidYouMean::SpellChecker.new(dictionary: @tasks.keys).correct(task_name.to_s)
::DidYouMean::Formatter.new(suggestions).to_s
else
""
end
def generate_did_you_mean_suggestions(task_name)
return "" unless defined?(::DidYouMean::SpellChecker)

message + suggestion_message
suggestions = ::DidYouMean::SpellChecker.new(dictionary: @tasks.keys).correct(task_name.to_s)
if ::DidYouMean.respond_to?(:formatter)# did_you_mean v1.2.0 or later
::DidYouMean.formatter.message_for(suggestions)
elsif defined?(::DidYouMean::Formatter) # before did_you_mean v1.2.0
::DidYouMean::Formatter.new(suggestions).to_s
else
""
end
end

def synthesize_file_task(task_name) # :nodoc:
Expand Down