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