Class/Module Index [+]

Quicksearch

Rails::Generator::NamedBase

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.

Attributes

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

Public Class Methods

new(runtime_args, runtime_options = {}) click to toggle source
# File lib/rails_generator/base.rb, line 206
def initialize(runtime_args, runtime_options = {})
  super

  # Name argument is required.
  usage if runtime_args.empty?

  @args = runtime_args.dup
  base_name = @args.shift
  assign_names!(base_name)
end

Protected Instance Methods

attributes() click to toggle source
# File lib/rails_generator/base.rb, line 223
def attributes
  @attributes ||= @args.collect do |attribute|
    Rails::Generator::GeneratedAttribute.new(*attribute.split(":"))
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.