Rails::Generator is a code generation platform tailored for the Rails web application framework. Generators are easily invoked within Rails applications to add and remove components such as models and controllers. New generators are easy to create and may be distributed as RubyGems, tarballs, or Rails plugins for inclusion system-wide, per-user, or per-application.

For actual examples see the rails_generator/generators directory in the Rails source (or the railties directory if you have frozen the Rails source in your application).

Generators may subclass other generators to provide variations that require little or no new logic but replace the template files.

For a RubyGem, put your generator class and templates in the lib directory. For a Rails plugin, make a generators directory at the root of your plugin.

The layout of generator files can be seen in the built-in controller generator:

  generators/
    components/
      controller/
        controller_generator.rb
        templates/
          controller.rb
          functional_test.rb
          helper.rb
          view.html.erb

The directory name (controller) matches the name of the generator file (controller_generator.rb) and class (ControllerGenerator). The files that will be copied or used as templates are stored in the templates directory.

The filenames of the templates don‘t matter, but choose something that will be self-explanatory since you will be referencing these in the manifest method inside your generator subclass.

Classes and Modules
Module Rails::Generator::Commands
Module Rails::Generator::Lookup
Module Rails::Generator::Options
Module Rails::Generator::Scripts
Class Rails::Generator::AbstractGemSource
Class Rails::Generator::Base
Class Rails::Generator::GemGeneratorSource
Class Rails::Generator::GemPathSource
Class Rails::Generator::GeneratedAttribute
Class Rails::Generator::GeneratorError
Class Rails::Generator::Manifest
Class Rails::Generator::NamedBase
Class Rails::Generator::PathSource
Class Rails::Generator::Source
Class Rails::Generator::Spec
Class Rails::Generator::UsageError