Class Rails::Generator::NamedBase
In: vendor/rails/railties/lib/rails_generator/base.rb
Parent: Base

The base generator for named components: models, controllers, mailers, etc. The target name is taken as the first argument and inflected to singular, plural, class, file, and table forms for your convenience. The remaining arguments are aliased to actions as an array for controller and mailer convenience.

Several useful local variables and methods are populated in the initialize method. See below for a list of Attributes and External Aliases available to both the manifest and to all templates.

If no name is provided, the generator raises a usage error with content optionally read from the USAGE file in the generator‘s base path.

For example, the controller generator takes the first argument as the name of the class and subsequent arguments as the names of actions to be generated:

  ./script/generate controller Article index new create

See Rails::Generator::Base for a discussion of manifests, Rails::Generator::Commands::Create for methods available to the manifest, and Rails::Generator for a general discussion of generators.

Methods

attributes   banner   new  

External Aliases

singular_name -> file_name
args -> actions

Attributes

class_name  [R] 
class_nesting  [R] 
class_nesting_depth  [R] 
class_path  [R] 
file_path  [R] 
name  [R] 
plural_name  [R] 
singular_name  [R] 
table_name  [R] 

Public Class methods

[Source]

     # File vendor/rails/railties/lib/rails_generator/base.rb, line 203
203:       def initialize(runtime_args, runtime_options = {})
204:         super
205: 
206:         # Name argument is required.
207:         usage if runtime_args.empty?
208: 
209:         @args = runtime_args.dup
210:         base_name = @args.shift
211:         assign_names!(base_name)
212:       end

Protected Instance methods

[Source]

     # File vendor/rails/railties/lib/rails_generator/base.rb, line 220
220:         def attributes
221:           @attributes ||= @args.collect do |attribute|
222:             Rails::Generator::GeneratedAttribute.new(*attribute.split(":"))
223:           end
224:         end

Override with your own usage banner.

[Source]

     # File vendor/rails/railties/lib/rails_generator/base.rb, line 216
216:         def banner
217:           "Usage: #{$0} #{spec.name} #{spec.name.camelize}Name [options]"
218:         end

[Validate]