Module: ActiveRecord::PGEnum::CommandRecorder

Defined in:
lib/active_record/pg_enum/command_recorder.rb

Overview

ActiveRecord::Migration::CommandRecorder is a class used by reversible migrations. It captures the forward migration commands and translates them into their inverse by way of some simple metaprogramming.

The Migrator class uses CommandRecorder during the reverse migration instead of the connection object. Forward migration calls are translated to their inverse where possible, and then forwarded to the connetion. Irreversible migrations raise an exception.

Known schema statement methods are metaprogrammed into an inverse method like so:

create_table => invert_create_table

which returns:

[:drop_table, args.first]

Instance Method Summary collapse

Instance Method Details

#add_enum_value(*args, &block) ⇒ Object



33
34
35
# File 'lib/active_record/pg_enum/command_recorder.rb', line 33

def add_enum_value(*args, &block)
  record(:add_enum_value, args, &block)
end

#create_enum(*args, &block) ⇒ Object



25
26
27
# File 'lib/active_record/pg_enum/command_recorder.rb', line 25

def create_enum(*args, &block)
  record(:create_enum, args, &block)
end

#drop_enum(*args, &block) ⇒ Object



29
30
31
# File 'lib/active_record/pg_enum/command_recorder.rb', line 29

def drop_enum(*args, &block)
  record(:drop_enum, args, &block)
end

#rename_enum(name, options = {}) ⇒ Object



37
38
39
# File 'lib/active_record/pg_enum/command_recorder.rb', line 37

def rename_enum(name, options = {})
  record(:rename_enum, [name, options])
end

#rename_enum_value(type, options = {}) ⇒ Object



41
42
43
# File 'lib/active_record/pg_enum/command_recorder.rb', line 41

def rename_enum_value(type, options = {})
  record(:rename_enum_value, [type, options])
end