Object
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
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 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
# File lib/active_record/migration/command_recorder.rb, line 69 69: def invert_add_column(args) 70: [:remove_column, args.first(2)] 71: end
# File lib/active_record/migration/command_recorder.rb, line 81 81: def invert_add_index(args) 82: table, columns, options = *args 83: index_name = options.try(:[], :name) 84: options_hash = index_name ? {:name => index_name} : {:column => columns} 85: [:remove_index, [table, options_hash]] 86: end
# File lib/active_record/migration/command_recorder.rb, line 92 92: def invert_add_timestamps(args) 93: [:remove_timestamps, args] 94: end
# File lib/active_record/migration/command_recorder.rb, line 61 61: def invert_create_table(args) 62: [:drop_table, [args.first]] 63: end
# File lib/active_record/migration/command_recorder.rb, line 88 88: def invert_remove_timestamps(args) 89: [:add_timestamps, args] 90: end
# File lib/active_record/migration/command_recorder.rb, line 77 77: def invert_rename_column(args) 78: [:rename_column, [args.first] + args.last(2).reverse] 79: end
# File lib/active_record/migration/command_recorder.rb, line 73 73: def invert_rename_index(args) 74: [:rename_index, [args.first] + args.last(2).reverse] 75: end
# File lib/active_record/migration/command_recorder.rb, line 65 65: def invert_rename_table(args) 66: [:rename_table, args.reverse] 67: end
Forwards any missing method call to the target.
# File lib/active_record/migration/command_recorder.rb, line 97 97: def method_missing(method, *args, &block) 98: @delegate.send(method, *args, &block) 99: rescue NoMethodError => e 100: raise e, e.message.sub(/ for #<.*$/, " via proxy for #{@delegate}") 101: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.