class Sequel::MigrationReverser

  1. lib/sequel/extensions/migration.rb
Superclass: BasicObject

Handles the reversing of reversible migrations. Basically records supported methods calls, translates them to reversed calls, and returns them in reverse order.

Methods

Public Class

  1. new

Public Instance

  1. reverse

Public Class methods

new ()
[show source]
# File lib/sequel/extensions/migration.rb, line 164
def initialize
  @actions = []
end

Public Instance methods

reverse (&block)

Reverse the actions for the given block. Takes the block given and returns a new block that reverses the actions taken by the given block.

[show source]
# File lib/sequel/extensions/migration.rb, line 171
def reverse(&block)
  begin
    instance_exec(&block)
  rescue
    just_raise = true
  end
  if just_raise
    Proc.new{raise Sequel::Error, 'irreversible migration method used, you may need to write your own down method'}
  else
    actions = @actions.reverse
    Proc.new do
      actions.each do |a|
        pr = a.last.is_a?(Proc) ? a.pop : nil
        # Allow calling private methods as the reversing methods are private
        send(*a, &pr)
      end
    end
  end
end