| 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 164
164: def reverse(&block)
165: begin
166: instance_eval(&block)
167: rescue
168: just_raise = true
169: end
170: if just_raise
171: Proc.new{raise Sequel::Error, 'irreversible migration method used, you may need to write your own down method'}
172: else
173: actions = @actions.reverse
174: Proc.new do
175: actions.each do |a|
176: if a.last.is_a?(Proc)
177: pr = a.pop
178: send(*a, &pr)
179: else
180: send(*a)
181: end
182: end
183: end
184: end
185: end