aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-08-03 19:36:37 +0100
committerJon Leighton <j@jonathanleighton.com>2012-08-03 19:36:37 +0100
commit5fe923cc341b5487fff2b7f2862829367ebd5102 (patch)
tree7d67991ab3a2389aac706f1561a9ca8a63e4e88b /activerecord/lib/active_record
parent6fe119650c4e18b68b85edea3761837bc6a8c921 (diff)
downloadrails-5fe923cc341b5487fff2b7f2862829367ebd5102.tar.gz
rails-5fe923cc341b5487fff2b7f2862829367ebd5102.tar.bz2
rails-5fe923cc341b5487fff2b7f2862829367ebd5102.zip
Make ActiveRecord::Model::DeprecationProxy work better
Closes #6600
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/base.rb2
-rw-r--r--activerecord/lib/active_record/model.rb49
2 files changed, 32 insertions, 19 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 6df68bade0..a4705b24ca 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -325,4 +325,4 @@ module ActiveRecord #:nodoc:
end
end
-ActiveSupport.run_load_hooks(:active_record, ActiveRecord::Model::DeprecationProxy)
+ActiveSupport.run_load_hooks(:active_record, ActiveRecord::Model::DeprecationProxy.new)
diff --git a/activerecord/lib/active_record/model.rb b/activerecord/lib/active_record/model.rb
index 3d0a39e979..a326dabcd3 100644
--- a/activerecord/lib/active_record/model.rb
+++ b/activerecord/lib/active_record/model.rb
@@ -109,26 +109,39 @@ module ActiveRecord
end
end
- module DeprecationProxy #:nodoc:
- class << self
- instance_methods.each { |m| undef_method m unless m =~ /^__|^object_id$|^instance_eval$/ }
-
- def method_missing(name, *args, &block)
- if Model.respond_to?(name)
- Model.send(name, *args, &block)
- else
- ActiveSupport::Deprecation.warn(
- "The object passed to the active_record load hook was previously ActiveRecord::Base " \
- "(a Class). Now it is ActiveRecord::Model (a Module). You have called `#{name}' which " \
- "is only defined on ActiveRecord::Base. Please change your code so that it works with " \
- "a module rather than a class. (Model is included in Base, so anything added to Model " \
- "will be available on Base as well.)"
- )
- Base.send(name, *args, &block)
- end
+ class DeprecationProxy < BasicObject #:nodoc:
+ def initialize(model = Model, base = Base)
+ @model = model
+ @base = base
+ end
+
+ def method_missing(name, *args, &block)
+ if @model.respond_to?(name, true)
+ @model.send(name, *args, &block)
+ else
+ ::ActiveSupport::Deprecation.warn(
+ "The object passed to the active_record load hook was previously ActiveRecord::Base " \
+ "(a Class). Now it is ActiveRecord::Model (a Module). You have called `#{name}' which " \
+ "is only defined on ActiveRecord::Base. Please change your code so that it works with " \
+ "a module rather than a class. (Model is included in Base, so anything added to Model " \
+ "will be available on Base as well.)"
+ )
+ @base.send(name, *args, &block)
end
+ end
- alias send method_missing
+ alias send method_missing
+
+ def extend(*mods)
+ ::ActiveSupport::Deprecation.warn(
+ "The object passed to the active_record load hook was previously ActiveRecord::Base " \
+ "(a Class). Now it is ActiveRecord::Model (a Module). You have called `extend' which " \
+ "would add singleton methods to Model. This is presumably not what you want, since the " \
+ "methods would not be inherited down to Base. Rather than using extend, please use " \
+ "ActiveSupport::Concern + include, which will ensure that your class methods are " \
+ "inherited."
+ )
+ @base.extend *mods
end
end
end