From 6519df4157a861c9c9d567ee57983ded0e967a10 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 19 Nov 2010 09:26:11 -0800 Subject: command recorder will record commands sent to a delegate object --- .../lib/active_record/migration/command_recorder.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'activerecord/lib') 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] -- cgit v1.2.3