命名空间
- 模块 Rails::Generators::Actions
- 模块 Rails::Generators::Db
- 模块 Rails::Generators::Migration
- 模块 Rails::Generators::Testing
- 类 Rails::Generators::ActiveModel
- 类 Rails::Generators::AppBase
- 类 Rails::Generators::AppGenerator
- 类 Rails::Generators::Base
- 类 Rails::Generators::BenchmarkGenerator
- 类 Rails::Generators::Database
- 类 Rails::Generators::NamedBase
- 类 Rails::Generators::ScriptGenerator
- 类 Rails::Generators::TestCase
方法
- A
- C
- F
- H
- I
- L
- P
- S
常量
| DEFAULT_ALIASES | = | { rails: { actions: "-a", orm: "-o", javascripts: ["-j", "--js"], resource_controller: "-c", scaffold_controller: "-c", stylesheets: "-y", template_engine: "-e", test_framework: "-t" }, test_unit: { fixture_replacement: "-r", } } |
| DEFAULT_OPTIONS | = | { rails: { api: false, assets: true, force_plural: false, helper: true, integration_tool: nil, orm: false, resource_controller: :controller, resource_route: true, scaffold_controller: :scaffold_controller, system_tests: nil, test_framework: nil, template_engine: :erb } } |
类公共方法
fallbacks() 链接
help(command = "generate") 链接
显示可用生成器的帮助消息。
# File railties/lib/rails/generators.rb, line 172 def help(command = "generate") puts "Usage:" puts " bin/rails #{command} GENERATOR [args] [options]" puts puts "General options:" puts " -h, [--help] # Print generator's options and usage" puts " -p, [--pretend] # Run but do not make any changes" puts " -f, [--force] # Overwrite files that already exist" puts " -s, [--skip] # Skip files that already exist" puts " -q, [--quiet] # Suppress status output" puts puts "Please choose a generator below." puts print_generators end
hidden_namespaces() 链接
返回一个隐藏的生成器命名空间数组。生成器命名空间可能由于多种原因而被隐藏。有些被别名为“rails:migration”,可以使用更短的“migration”来调用。
来源: | 在GitHub上
invoke(namespace, args = ARGV, config = {}) 链接
接收一个命名空间、参数和要调用的生成器的行为。它被用作generate、destroy和update命令的默认入口点。
# File railties/lib/rails/generators.rb, line 263 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) error = Command::CorrectableNameError.new("Could not find generator '#{namespace}'.", namespace, options) puts <<~MSG #{error.detailed_message} Run `bin/rails generate --help` for more options. MSG exit 1 end end
print_generators() 链接
public_namespaces() 链接
sorted_groups() 链接
# File railties/lib/rails/generators.rb, line 198 def sorted_groups namespaces = public_namespaces namespaces.sort! groups = Hash.new { |h, k| h[k] = [] } namespaces.each do |namespace| base = namespace.split(":").first groups[base] << namespace end rails = groups.delete("rails") rails.map! { |n| n.delete_prefix("rails:") } rails.delete("app") rails.delete("plugin") rails.delete("encrypted_file") rails.delete("encryption_key_file") rails.delete("master_key") rails.delete("credentials") rails.delete("db:system:change") hidden_namespaces.each { |n| groups.delete(n.to_s) } [[ "rails", rails ]] + groups.sort.to_a end