Rails-Generator 是什么的一个很好的定义?

A good definition for what a Rails-Generator is?

什么是 Rails 生成器?

它们是脚本,用于创建文件and/or 样板代码吗?

我找不到关于它们实际是什么的良好定义...

发电机不只是由 Rails 自己提供?像 rspec 这样的 Gem 可以将发电机添加到 Rails 并且在安装后 Rails 有额外的发电机吗?我做对了吗?

Are they scripts, which are used to create files and/or boilerplate code?

是的,我认为这是一个很好的定义。这是 Rails 文档中的两个定义(尽管我同意它们有点含糊)。

The rails generate command uses templates to create a whole lot of things

Rails scaffolding is a quick way to generate some of the major pieces of an application.

总而言之,生成器通常是 Rake task,它确实使用模板文件来创建样板代码。这有助于快速开发应用程序。

Generators aren't just provided by Rails itself? Gems like rspec can add Generators to Rails and after an install Rails has that additional Generators? Do I get that right?

是的,如果您的 gem 是 Railties,您可以安装额外的发电机。

Rails::Railtie is the core of the Rails framework and provides several hooks to extend Rails and/or modify the initialization process.

这里有一个例子 template from RSpec.

https://api.rubyonrails.org/classes/Rails/Railtie.html https://api.rubyonrails.org/classes/Rails/Generators.html