invoke(namespace, args = ARGV, config = {}) public Receives a namespace, arguments and the behavior to invoke the generator. It’s used as the default entry point for generate, destroy and update commands.
Show source def invoke(namespace, args = ARGV, config = {}) names = namespace.to_s.split(":") if klass = find_by_namespace(names.pop, names.any? && names.join(":")) args << "--help" if args.empty? && klass.arguments.any?(&:required?) klass.start(args, config) run_after_generate_callback if config[:behavior] == :invoke else options = sorted_groups.flat_map(&:last) suggestion = Rails::Command::Spellchecker.suggest(namespace.to_s, from: options) suggestion_msg = "Maybe you meant #{suggestion.inspect}?" if suggestion puts <<~MSG Could not find generator '#{namespace}'. Run `bin/rails generate --help` for more options. MSG end end def add_generated_file(file) (@@generated_files ||= []) << file file end private def print_list(base, namespaces) namespaces = namespaces.reject { |n| hidden_namespaces.include?(n) } super end def invoke_fallbacks_for(name, base) return nil unless base && fallbacks[base.to_sym] invoked_fallbacks = [] Array(fallbacks[base.to_sym]).each do |fallback| next if invoked_fallbacks.include?(fallback) invoked_fallbacks << fallback klass = find_by_namespace(name, fallback) return klass if klass end nil end def command_type @command_type ||= "generator" end def lookup_paths @lookup_paths ||= %( rails/generators generators ) end def file_lookup_paths @file_lookup_paths ||= [ "{#{lookup_paths.join(',')}}", "**", "*_generator.rb" ] end def run_after_generate_callback if defined?(@@generated_files) && !@@generated_files.empty? @after_generate_callbacks.each do |callback| callback.call(@@generated_files) end @@generated_files = [] end end end