diff options
author | Michael Koziarski <michael@koziarski.com> | 2008-02-08 23:35:33 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2008-02-08 23:35:33 +0000 |
commit | cadb087deb76e477d5bf557bd3ca67c569095706 (patch) | |
tree | d59ea9d417397be9beedf7a0aed33530249111dd | |
parent | 3d1a30bc595b14820a7da60af39ff2d6f2a503e3 (diff) | |
download | rails-cadb087deb76e477d5bf557bd3ca67c569095706.tar.gz rails-cadb087deb76e477d5bf557bd3ca67c569095706.tar.bz2 rails-cadb087deb76e477d5bf557bd3ca67c569095706.zip |
Avoid cloning in Base#attributes. Closes #11047 [juanjo.bazan]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8824 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index d1729b6ff4..fc45930d73 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -2212,21 +2212,24 @@ module ActiveRecord #:nodoc: end - # Returns a hash of all the attributes with their names as keys and clones of their objects as values. + # Returns a hash of all the attributes with their names as keys and the values of the attributes as values. def attributes(options = nil) - attributes = clone_attributes :read_attribute + attrs = {} + self.attribute_names.each do |name| + attrs[name]=read_attribute(name) + end if options.nil? - attributes + attrs else if except = options[:except] except = Array(except).collect { |attribute| attribute.to_s } - except.each { |attribute_name| attributes.delete(attribute_name) } - attributes + except.each { |attribute_name| attrs.delete(attribute_name) } + attrs elsif only = options[:only] only = Array(only).collect { |attribute| attribute.to_s } - attributes.delete_if { |key, value| !only.include?(key) } - attributes + attrs.delete_if { |key, value| !only.include?(key) } + attrs else raise ArgumentError, "Options does not specify :except or :only (#{options.keys.inspect})" end |