diff options
Diffstat (limited to 'railties/lib/rails/generators.rb')
-rw-r--r-- | railties/lib/rails/generators.rb | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 3f1bf6a5bb..ed672ae48e 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -1,4 +1,6 @@ -activesupport_path = File.expand_path("../../../../activesupport/lib", __FILE__) +# frozen_string_literal: true + +activesupport_path = File.expand_path("../../../activesupport/lib", __dir__) $:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path) require "thor/group" @@ -10,6 +12,7 @@ require "active_support/core_ext/kernel/singleton_class" require "active_support/core_ext/array/extract_options" require "active_support/core_ext/hash/deep_merge" require "active_support/core_ext/module/attribute_accessors" +require "active_support/core_ext/string/indent" require "active_support/core_ext/string/inflections" module Rails @@ -63,7 +66,7 @@ module Rails stylesheet_engine: :css, scaffold_stylesheet: true, system_tests: nil, - test_framework: false, + test_framework: nil, template_engine: :erb } } @@ -123,7 +126,7 @@ module Rails ) if ARGV.first == "mailer" - options[:rails].merge!(template_engine: :erb) + options[:rails][:template_engine] = :erb end end @@ -215,6 +218,10 @@ module Rails rails.delete("app") rails.delete("plugin") rails.delete("encrypted_secrets") + rails.delete("encrypted_file") + rails.delete("encryption_key_file") + rails.delete("master_key") + rails.delete("credentials") hidden_namespaces.each { |n| groups.delete(n.to_s) } @@ -251,7 +258,6 @@ module Rails namespaces = Hash[subclasses.map { |klass| [klass.namespace, klass] }] lookups.each do |namespace| - klass = namespaces[namespace] return klass if klass end @@ -269,11 +275,11 @@ module Rails klass.start(args, config) else options = sorted_groups.flat_map(&:last) - 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}'" }.to_sentence(last_word_connector: " or ", locale: :en) }\n" - msg << "Run `rails generate --help` for more options." - puts msg + suggestion = Rails::Command::Spellchecker.suggest(namespace.to_s, from: options) + puts <<~MSG + Could not find generator '#{namespace}'. Maybe you meant #{suggestion.inspect}? + Run `rails generate --help` for more options. + MSG end end |