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
- class_collisions
- current_migration_number
- dependency
- existing_migrations
- gsub_file
- invoke!
- migration_directory
- migration_exists?
- next_migration_number
- next_migration_string
- readme
Public Instance methods
Does nothing for all commands except Create.
Replay action manifest. RewindBase subclass rewinds manifest.
Does nothing for all commands except Create.
Protected Instance methods
# File railties/lib/rails_generator/commands.rb, line 61
61: def current_migration_number
62: Dir.glob("#{RAILS_ROOT}/#{@migration_directory}/[0-9]*_*.rb").inject(0) do |max, file_path|
63: n = File.basename(file_path).split('_', 2).first.to_i
64: if n > max then n else max end
65: end
66: end
# File railties/lib/rails_generator/commands.rb, line 92
92: def gsub_file(relative_destination, regexp, *args, &block)
93: path = destination_path(relative_destination)
94: content = File.read(path).gsub(regexp, *args, &block)
95: File.open(path, 'wb') { |file| file.write(content) }
96: end