aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-12-14 14:49:02 +0000
committerJon Leighton <j@jonathanleighton.com>2011-12-14 14:51:57 +0000
commitbb44e5a80ac62f87a40122a213038a746f2bc289 (patch)
treefd897babdffa9e8e5a08d5dd45bfdea0b5f58078 /activerecord/lib/active_record/attribute_methods.rb
parenta5589db063e0f527357f6be338adecf4716e6b47 (diff)
downloadrails-bb44e5a80ac62f87a40122a213038a746f2bc289.tar.gz
rails-bb44e5a80ac62f87a40122a213038a746f2bc289.tar.bz2
rails-bb44e5a80ac62f87a40122a213038a746f2bc289.zip
Use a separate module for 'external' attribute methods.
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods.rb')
-rw-r--r--activerecord/lib/active_record/attribute_methods.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb
index 3c9fafb1ca..47f625039b 100644
--- a/activerecord/lib/active_record/attribute_methods.rb
+++ b/activerecord/lib/active_record/attribute_methods.rb
@@ -33,6 +33,20 @@ module ActiveRecord
@generated_attribute_methods ||= (base_class == self ? super : base_class.generated_attribute_methods)
end
+ def generated_external_attribute_methods
+ @generated_external_attribute_methods ||= begin
+ if base_class == self
+ # We will define the methods as instance methods, but will call them as singleton
+ # methods. This allows us to use method_defined? to check if the method exists,
+ # which is fast and won't give any false positives from the ancestors (because
+ # there are no ancestors).
+ Module.new { extend self }
+ else
+ base_class.generated_external_attribute_methods
+ end
+ end
+ end
+
def undefine_attribute_methods
if base_class == self
super