ActiveRecord::Migration::CommandRecorder records commands done during a migration and knows how to reverse those commands. The CommandRecorder knows how to invert the following commands:

  • add_column
  • add_index
  • add_timestamps
  • create_table
  • remove_timestamps
  • rename_column
  • rename_index
  • rename_table
Methods
I
N
R
Attributes
[RW] commands
[RW] delegate
Class Public methods
new(delegate = nil)
    # File activerecord/lib/active_record/migration/command_recorder.rb, line 18
18:       def initialize(delegate = nil)
19:         @commands = []
20:         @delegate = delegate
21:       end
Instance Public methods
inverse()

Returns a list that represents commands that are the inverse of the commands stored in commands. For example:

  recorder.record(:rename_table, [:old, :new])
  recorder.inverse # => [:rename_table, [:new, :old]]

This method will raise an IrreversibleMigration exception if it cannot invert the commands.

    # File activerecord/lib/active_record/migration/command_recorder.rb, line 39
39:       def inverse
40:         @commands.reverse.map { |name, args|
41:           method = :"invert_#{name}"
42:           raise IrreversibleMigration unless respond_to?(method, true)
43:           send(method, args)
44:         }
45:       end
record(*command)

record command. command should be a method name and arguments. For example:

  recorder.record(:method_name, [:arg1, :arg2])
    # File activerecord/lib/active_record/migration/command_recorder.rb, line 27
27:       def record(*command)
28:         @commands << command
29:       end