Parent

Files

Class/Module Index [+]

Quicksearch

ActiveRecord::Migration::CommandRecorder

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:

Attributes

commands[RW]
delegate[RW]

Public Class Methods

new(delegate = nil) click to toggle source
# File lib/active_record/migration/command_recorder.rb, line 18
def initialize(delegate = nil)
  @commands = []
  @delegate = delegate
end

Public Instance Methods

inverse() click to toggle source

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 lib/active_record/migration/command_recorder.rb, line 39
def inverse
  @commands.reverse.map { |name, args|
    method = :"invert_#{name}"
    raise IrreversibleMigration unless respond_to?(method, true)
    send(method, args)
  }
end
record(*command) click to toggle source

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

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.