Generator commands delegate Rails::Generator::Base and implement a standard set of actions. Their behavior is defined by the way they respond to these actions: Create brings life; Destroy brings death; List passively observes.

Commands are invoked by replaying (or rewinding) the generator's manifest of actions. See Rails::Generator::Manifest and Rails::Generator::Base#manifest method that generator subclasses are required to override.

Commands allows generators to "plug in" invocation behavior, which corresponds to the GoF Strategy pattern.

Methods
C
D
E
G
I
M
N
R
Instance Public methods
class_collisions(*class_names)

Does nothing for all commands except Create.

# File rails/railties/lib/rails_generator/commands.rb, line 52
def class_collisions(*class_names)
end
dependency(generator_name, args, runtime_options = {})
# File rails/railties/lib/rails_generator/commands.rb, line 45
def dependency(generator_name, args, runtime_options = {})
  logger.dependency(generator_name) do
    self.class.new(instance(generator_name, args, full_options(runtime_options))).invoke!
  end
end
invoke!()

Replay action manifest. RewindBase subclass rewinds manifest.

# File rails/railties/lib/rails_generator/commands.rb, line 41
def invoke!
  manifest.replay(self)
end
readme(*args)

Does nothing for all commands except Create.

# File rails/railties/lib/rails_generator/commands.rb, line 56
def readme(*args)
end
Instance Protected methods
current_migration_number()
# File rails/railties/lib/rails_generator/commands.rb, line 72
def current_migration_number
  Dir.glob("#{@migration_directory}/[0-9]*.rb").inject(0) do |max, file_path|
    n = File.basename(file_path).split('_', 2).first.to_i
    if n > max then n else max end
  end
end
existing_migrations(file_name)
# File rails/railties/lib/rails_generator/commands.rb, line 64
def existing_migrations(file_name)
  Dir.glob("#{@migration_directory}/[0-9]*_*.rb").grep(%r[0-9]+_#{file_name}.rb$/)
end
gsub_file(relative_destination, regexp, *args, &block)
# File rails/railties/lib/rails_generator/commands.rb, line 87
def gsub_file(relative_destination, regexp, *args, &block)
  path = destination_path(relative_destination)
  content = File.read(path).gsub(regexp, *args, &block)
  File.open(path, 'wb') { |file| file.write(content) }
end
migration_directory(relative_path)
# File rails/railties/lib/rails_generator/commands.rb, line 60
def migration_directory(relative_path)
  directory(@migration_directory = relative_path)
end
migration_exists?(file_name)
# File rails/railties/lib/rails_generator/commands.rb, line 68
def migration_exists?(file_name)
  not existing_migrations(file_name).empty?
end
next_migration_number()
# File rails/railties/lib/rails_generator/commands.rb, line 79
def next_migration_number
  current_migration_number + 1
end
next_migration_string(padding = 3)
# File rails/railties/lib/rails_generator/commands.rb, line 83
def next_migration_string(padding = 3)
  "%.#{padding}d" % next_migration_number
end