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

Backport: fix the Levenshtein distance implementation #19151

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions railties/lib/rails/generators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def self.invoke(namespace, args=ARGV, config={})
options = sorted_groups.map(&:last).flatten
suggestions = options.sort_by {|suggested| levenshtein_distance(namespace.to_s, suggested) }.first(3)
msg = "Could not find generator '#{namespace}'. "
msg << "Maybe you meant #{ suggestions.map {|s| "'#{s}'"}.join(" or ") }\n"
msg << "Maybe you meant #{ suggestions.map {|s| "'#{s}'"}.to_sentence(last_word_connector: " or ") }\n"
msg << "Run `rails generate --help` for more options."
puts msg
end
Expand Down Expand Up @@ -260,11 +260,9 @@ def self.levenshtein_distance str1, str2
t = str2
n = s.length
m = t.length
max = n/2

return m if (0 == n)
return n if (0 == m)
return n if (n - m).abs > max

d = (0..m).to_a
x = nil
Expand Down