diff options
author | Rick Olson <technoweenie@gmail.com> | 2007-10-06 00:25:07 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2007-10-06 00:25:07 +0000 |
commit | 5b2e8b1eb1731e987faa233dc03e83c221cfcda5 (patch) | |
tree | 0eaf4449eee8b31e7e48f9f29068e4fb5ef81c81 /activerecord/lib | |
parent | 24c2457a26983c323f0c90d175c00453d853f3b6 (diff) | |
download | rails-5b2e8b1eb1731e987faa233dc03e83c221cfcda5.tar.gz rails-5b2e8b1eb1731e987faa233dc03e83c221cfcda5.tar.bz2 rails-5b2e8b1eb1731e987faa233dc03e83c221cfcda5.zip |
Fix that ActiveRecord would create attribute methods and override custom attribute getters if the method is also defined in Kernel.methods. [Rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7749 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods.rb | 16 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 9 |
2 files changed, 13 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 695e9caae3..b17f72741a 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -76,20 +76,18 @@ module ActiveRecord end end + # Check to see if the method is defined in the model or any of it's subclasses that also derive from ActiveRecord. + # Raise DangerousAttributeError if the method is defined by ActiveRecord though. def instance_method_already_implemented?(method_name) - if method_defined?(method_name) || private_method_defined?(method_name) || protected_method_defined?(method_name) - # method is defined but maybe its a simple Kernel:: method which we could simply override - @@_overrideable_kernel_methods ||= Set.new(Kernel.methods) - !@@_overrideable_kernel_methods.include?(method_name) - else - false - end + return true if method_name =~ /^id(=$|\?$|$)/ + @_defined_class_methods ||= Set.new(ancestors.first(ancestors.index(ActiveRecord::Base)).collect! { |m| m.public_instance_methods(false) | m.private_instance_methods(false) | m.protected_instance_methods(false) }.flatten) + @@_defined_activerecord_methods ||= Set.new(ActiveRecord::Base.public_instance_methods(false) | ActiveRecord::Base.private_instance_methods(false) | ActiveRecord::Base.protected_instance_methods(false)) + raise DangerousAttributeError, "#{method_name} is defined by ActiveRecord" if @@_defined_activerecord_methods.include?(method_name) + @_defined_class_methods.include?(method_name) end alias :define_read_methods :define_attribute_methods - - private # Suffixes a, ?, c become regexp /(a|\?|c)$/ def rebuild_attribute_method_regexp diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index df15457a9a..5e1185065e 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -29,11 +29,14 @@ module ActiveRecord #:nodoc: end class StaleObjectError < ActiveRecordError #:nodoc: end - class ConfigurationError < StandardError #:nodoc: + class ConfigurationError < ActiveRecordError #:nodoc: end - class ReadOnlyRecord < StandardError #:nodoc: + class ReadOnlyRecord < ActiveRecordError #:nodoc: end - class Rollback < StandardError #:nodoc: + class Rollback < ActiveRecordError #:nodoc: + end + + class DangerousAttributeError < ActiveRecordError #:nodoc: end # Raised when you've tried to access a column, which wasn't |