method
invoke
v6.0.0 -
Show latest stable
- Class:
Rails::Generators
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.
# File railties/lib/rails/generators.rb, line 272
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)
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}'. #{suggestion_msg}
Run `rails generate --help` for more options.
MSG
end
end
private
def print_list(base, namespaces) # :doc:
namespaces = namespaces.reject { |n| hidden_namespaces.include?(n) }
super
end
# Try fallbacks for the given base.
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 # :doc:
@command_type ||= "generator"
end
def lookup_paths # :doc:
@lookup_paths ||= %( rails/generators generators )
end
def file_lookup_paths # :doc:
@file_lookup_paths ||= [ "{#{lookup_paths.join(',')}}", "**", "*_generator.rb" ]
end
end