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.
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/ controller/ controller_generator.rb templates/ controller.rb functional_test.rb helper.rb view.rhtml
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-explatatory since you will be referencing these in the manifest method inside your generator subclass.
railties/lib/rails_generator/manifest.rb railties/lib/rails_generator/simple_logger.rb railties/lib/rails_generator/spec.rb railties/lib/rails_generator/scripts.rb railties/lib/rails_generator/base.rb railties/lib/rails_generator/commands.rb railties/lib/rails_generator/generated_attribute.rb railties/lib/rails_generator/lookup.rb railties/lib/rails_generator/options.rb