| Class | Sequel::MigrationReverser |
| In: |
lib/sequel/extensions/migration.rb
|
| Parent: | Sequel::BasicObject |
Handles the reversing of reversible migrations. Basically records supported methods calls, translates them to reversed calls, and returns them in reverse order.
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.
# File lib/sequel/extensions/migration.rb, line 132
132: def reverse(&block)
133: begin
134: instance_eval(&block)
135: rescue
136: just_raise = true
137: end
138: if just_raise
139: Proc.new{raise Sequel::Error, 'irreversible migration method used, you may need to write your own down method'}
140: else
141: actions = @actions.reverse
142: Proc.new do
143: actions.each do |a|
144: if a.last.is_a?(Proc)
145: pr = a.pop
146: send(*a, &pr)
147: else
148: send(*a)
149: end
150: end
151: end
152: end
153: end