Handles the reversing of reversible migrations. Basically records supported methods calls, translates them to reversed calls, and returns them in reverse order.
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 instance_exec(&block) 190 rescue NoMethodError => e 191 Proc.new{raise Sequel::Error, "irreversible migration method \"#{e.name}\" used in #{block.source_location.first}, you may need to write your own down method"} 192 rescue => e 193 Proc.new{raise Sequel::Error, "unable to reverse migration due to #{e.class} in #{block.source_location.first}, you may need to write your own down method"} 194 else 195 actions = @actions.reverse 196 Proc.new do 197 actions.each do |a| 198 pr = a.last.is_a?(Proc) ? a.pop : nil 199 # Allow calling private methods as the reversing methods are private 200 send(*a, &pr) 201 end 202 end 203 end