Class: Reactive::NamedBaseGenerator

Inherits:
RubiGen::Base
  • Object
show all
Defined in:
lib/named_base_generator.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runtime_args, runtime_options = {}) ⇒ NamedBaseGenerator

Returns a new instance of NamedBaseGenerator.



32
33
34
35
36
37
38
39
40
41
# File 'lib/named_base_generator.rb', line 32

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

Instance Attribute Details

#class_nameObject (readonly)

Returns the value of attribute class_name.



27
28
29
# File 'lib/named_base_generator.rb', line 27

def class_name
  @class_name
end

#class_nestingObject (readonly)

Returns the value of attribute class_nesting.



28
29
30
# File 'lib/named_base_generator.rb', line 28

def class_nesting
  @class_nesting
end

#class_nesting_depthObject (readonly)

Returns the value of attribute class_nesting_depth.



28
29
30
# File 'lib/named_base_generator.rb', line 28

def class_nesting_depth
  @class_nesting_depth
end

#class_pathObject (readonly)

Returns the value of attribute class_path.



28
29
30
# File 'lib/named_base_generator.rb', line 28

def class_path
  @class_path
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



28
29
30
# File 'lib/named_base_generator.rb', line 28

def file_path
  @file_path
end

#nameObject (readonly)

Returns the value of attribute name.



27
28
29
# File 'lib/named_base_generator.rb', line 27

def name
  @name
end

#plural_nameObject (readonly)

Returns the value of attribute plural_name.



27
28
29
# File 'lib/named_base_generator.rb', line 27

def plural_name
  @plural_name
end

#singular_nameObject (readonly) Also known as: file_name

Returns the value of attribute singular_name.



27
28
29
# File 'lib/named_base_generator.rb', line 27

def singular_name
  @singular_name
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



27
28
29
# File 'lib/named_base_generator.rb', line 27

def table_name
  @table_name
end