aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-11-19 09:26:11 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2010-11-19 10:24:16 -0800
commit6519df4157a861c9c9d567ee57983ded0e967a10 (patch)
tree14de75a1542137d115b67b6ba81d69a65d8f8cbe /activerecord/lib
parent6dbbfae5638a6c847fd63d52a72247e2bb15a320 (diff)
downloadrails-6519df4157a861c9c9d567ee57983ded0e967a10.tar.gz
rails-6519df4157a861c9c9d567ee57983ded0e967a10.tar.bz2
rails-6519df4157a861c9c9d567ee57983ded0e967a10.zip
command recorder will record commands sent to a delegate object
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/migration/command_recorder.rb16
1 files changed, 13 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/migration/command_recorder.rb b/activerecord/lib/active_record/migration/command_recorder.rb
index 8a98a177d5..fa189b8009 100644
--- a/activerecord/lib/active_record/migration/command_recorder.rb
+++ b/activerecord/lib/active_record/migration/command_recorder.rb
@@ -3,10 +3,11 @@ module ActiveRecord
# ActiveRecord::Migration::CommandRecorder records commands done during
# a migration and knows how to reverse those commands.
class CommandRecorder
- attr_reader :commands
+ attr_reader :commands, :delegate
- def initialize
+ def initialize(delegate = nil)
@commands = []
+ @delegate = delegate
end
# record +command+. +command+ should be a method name and arguments.
@@ -29,10 +30,19 @@ module ActiveRecord
@commands.reverse.map { |name, args|
method = :"invert_#{name}"
raise IrreversibleMigration unless respond_to?(method, true)
- send(method, args)
+ __send__(method, args)
}
end
+ def respond_to?(*args) # :nodoc:
+ super || delegate.respond_to?(*args)
+ end
+
+ def send(method, *args) # :nodoc:
+ return super unless respond_to?(method)
+ record(method, args)
+ end
+
private
def invert_create_table(args)
[:drop_table, args]