Class: Sequel::MigrationReverser
- Inherits:
- BasicObject
- Defined in:
- lib/sequel/extensions/migration.rb
Overview
Handles the reversing of reversible migrations. Basically records supported methods calls, translates them to reversed calls, and returns them in reverse order.
Constant Summary
Constants inherited from BasicObject
Instance Method Summary collapse
-
#initialize ⇒ MigrationReverser
constructor
A new instance of MigrationReverser.
-
#reverse(&block) ⇒ Object
Reverse the actions for the given block.
Methods inherited from BasicObject
const_missing, remove_methods!
Constructor Details
#initialize ⇒ MigrationReverser
Returns a new instance of MigrationReverser.
158 159 160 |
# File 'lib/sequel/extensions/migration.rb', line 158 def initialize @actions = [] end |
Instance Method Details
#reverse(&block) ⇒ Object
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.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/sequel/extensions/migration.rb', line 165 def reverse(&block) begin instance_eval(&block) rescue just_raise = true end if just_raise Proc.new{raise Sequel::Error, 'irreversible migration method used, you may need to write your own down method'} else actions = @actions.reverse Proc.new do actions.each do |a| if a.last.is_a?(Proc) pr = a.pop send(*a, &pr) else send(*a) end end end end end |