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
168 def initialize
169   @actions = []
170 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
175 def reverse(&block)
176   begin
177     instance_exec(&block)
178   rescue
179     just_raise = true
180   end
181   if just_raise
182     Proc.new{raise Sequel::Error, "irreversible migration method used in #{block.source_location.first}, you may need to write your own down method"}
183   else
184     actions = @actions.reverse
185     Proc.new do
186       actions.each do |a|
187         pr = a.last.is_a?(Proc) ? a.pop : nil
188         # Allow calling private methods as the reversing methods are private
189         send(*a, &pr)
190       end
191     end
192   end
193 end