Parent

Files

Class 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
18:       def initialize(delegate = nil)
19:         @commands = []
20:         @delegate = delegate
21:       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
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) 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
27:       def record(*command)
28:         @commands << command
29:       end

Private Instance Methods

invert_add_column(args) click to toggle source
    # File lib/active_record/migration/command_recorder.rb, line 69
69:       def invert_add_column(args)
70:         [:remove_column, args.first(2)]
71:       end
invert_add_index(args) click to toggle source
    # 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
invert_add_timestamps(args) click to toggle source
    # File lib/active_record/migration/command_recorder.rb, line 92
92:       def invert_add_timestamps(args)
93:         [:remove_timestamps, args]
94:       end
invert_create_table(args) click to toggle source
    # File lib/active_record/migration/command_recorder.rb, line 61
61:       def invert_create_table(args)
62:         [:drop_table, [args.first]]
63:       end
invert_remove_timestamps(args) click to toggle source
    # File lib/active_record/migration/command_recorder.rb, line 88
88:       def invert_remove_timestamps(args)
89:         [:add_timestamps, args]
90:       end
invert_rename_column(args) click to toggle source
    # 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
invert_rename_index(args) click to toggle source
    # 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
invert_rename_table(args) click to toggle source
    # File lib/active_record/migration/command_recorder.rb, line 65
65:       def invert_rename_table(args)
66:         [:rename_table, args.reverse]
67:       end
method_missing(method, *args, &block) click to toggle source

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.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.