diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-11-17 12:53:38 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-11-17 14:26:34 -0800 |
commit | 8b2f801ed8690dcbc61d62e6b3518efaac70a4a4 (patch) | |
tree | 594eb88747964b1d96109d81cb7912ee74ef6b42 /activerecord/lib/active_record | |
parent | fe2f168d40385a0412f41c1a2a44a5536cada8df (diff) | |
download | rails-8b2f801ed8690dcbc61d62e6b3518efaac70a4a4.tar.gz rails-8b2f801ed8690dcbc61d62e6b3518efaac70a4a4.tar.bz2 rails-8b2f801ed8690dcbc61d62e6b3518efaac70a4a4.zip |
converted migrations to support instance methods
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 40 | ||||
-rw-r--r-- | activerecord/lib/active_record/schema.rb | 6 |
2 files changed, 36 insertions, 10 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 diff --git a/activerecord/lib/active_record/schema.rb b/activerecord/lib/active_record/schema.rb index c1bc3214ea..a621248cc3 100644 --- a/activerecord/lib/active_record/schema.rb +++ b/activerecord/lib/active_record/schema.rb @@ -30,9 +30,7 @@ module ActiveRecord # ActiveRecord::Schema is only supported by database adapters that also # support migrations, the two features being very similar. class Schema < Migration - private_class_method :new - - def self.migrations_path + def migrations_path ActiveRecord::Migrator.migrations_path end @@ -48,7 +46,7 @@ module ActiveRecord # ... # end def self.define(info={}, &block) - instance_eval(&block) + new.instance_eval(&block) unless info[:version].blank? initialize_schema_migrations_table |