class Sequel::MigrationReverser

  1. lib/sequel/extensions/migration.rb
  2. lib/sequel/extensions/pg_enum.rb
  3. show all
Superclass: Sequel::BasicObject

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

:nocov:

Methods

Public Class

  1. new

Public Instance

  1. reverse

Public Class methods

new()
[show source]
    # File lib/sequel/extensions/migration.rb
181 def initialize
182   @actions = []
183 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
188 def reverse(&block)
189   begin
190     instance_exec(&block)
191   rescue
192     just_raise = true
193   end
194   if just_raise
195     Proc.new{raise Sequel::Error, "irreversible migration method used in #{block.source_location.first}, you may need to write your own down method"}
196   else
197     actions = @actions.reverse
198     Proc.new do
199       actions.each do |a|
200         pr = a.last.is_a?(Proc) ? a.pop : nil
201         # Allow calling private methods as the reversing methods are private
202         send(*a, &pr)
203       end
204     end
205   end
206 end