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