aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/migration.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-11-17 12:53:38 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2010-11-17 14:26:34 -0800
commit8b2f801ed8690dcbc61d62e6b3518efaac70a4a4 (patch)
tree594eb88747964b1d96109d81cb7912ee74ef6b42 /activerecord/lib/active_record/migration.rb
parentfe2f168d40385a0412f41c1a2a44a5536cada8df (diff)
downloadrails-8b2f801ed8690dcbc61d62e6b3518efaac70a4a4.tar.gz
rails-8b2f801ed8690dcbc61d62e6b3518efaac70a4a4.tar.bz2
rails-8b2f801ed8690dcbc61d62e6b3518efaac70a4a4.zip
converted migrations to support instance methods
Diffstat (limited to 'activerecord/lib/active_record/migration.rb')
-rw-r--r--activerecord/lib/active_record/migration.rb40
1 files changed, 34 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb
index 2c306d233a..4a1a84b74b 100644
--- a/activerecord/lib/active_record/migration.rb
+++ b/activerecord/lib/active_record/migration.rb
@@ -287,10 +287,30 @@ module ActiveRecord
# In application.rb.
#
class Migration
- @@verbose = true
- cattr_accessor :verbose
-
class << self
+ attr_accessor :verbose
+ attr_accessor :delegate # :nodoc:
+ def method_missing(name, *args, &block) # :nodoc:
+ (delegate || superclass.delegate).send(name, *args, &block)
+ end
+ end
+ self.delegate = new
+ self.verbose = true
+
+ def name
+ self.class.name
+ end
+
+ def up
+ self.class.delegate = self
+ self.class.up
+ end
+
+ def down
+ self.class.delegate = self
+ self.class.down
+ end
+
def up_with_benchmarks #:nodoc:
migrate(:up)
end
@@ -309,7 +329,7 @@ module ActiveRecord
end
result = nil
- time = Benchmark.measure { result = send("#{direction}_without_benchmarks") }
+ time = Benchmark.measure { result = send("#{direction}") }
case direction
when :up then announce "migrated (%.4fs)" % time.real; write
@@ -380,10 +400,19 @@ module ActiveRecord
unless arguments.empty? || method == :execute
arguments[0] = Migrator.proper_table_name(arguments.first)
end
+ return super unless connection.respond_to?(method)
connection.send(method, *arguments, &block)
end
end
+ def verbose
+ self.class.verbose
+ end
+
+ def verbose= verbosity
+ self.class.verbose = verbosity
+ end
+
def copy(destination, sources, options = {})
copied = []
@@ -425,7 +454,6 @@ module ActiveRecord
"%.3d" % number
end
end
- end
end
# MigrationProxy is used to defer loading of the actual migration classes
@@ -451,7 +479,7 @@ module ActiveRecord
def load_migration
require(File.expand_path(filename))
- name.constantize
+ name.constantize.new
end
end