diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-12-14 14:49:02 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-12-14 14:51:57 +0000 |
commit | bb44e5a80ac62f87a40122a213038a746f2bc289 (patch) | |
tree | fd897babdffa9e8e5a08d5dd45bfdea0b5f58078 /activerecord/lib/active_record/attribute_methods.rb | |
parent | a5589db063e0f527357f6be338adecf4716e6b47 (diff) | |
download | rails-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.rb | 14 |
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 |