aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/base.rb
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2008-02-13 02:19:46 +0000
committerMichael Koziarski <michael@koziarski.com>2008-02-13 02:19:46 +0000
commit08a4c9979da44654f057494dc76498ed6a8506bc (patch)
treedecf0d8dd6c8715f57d59923543fb193dec8ede7 /activerecord/lib/active_record/base.rb
parent46356100d1518c67d005be1fecceb9aea4c72dfd (diff)
downloadrails-08a4c9979da44654f057494dc76498ed6a8506bc.tar.gz
rails-08a4c9979da44654f057494dc76498ed6a8506bc.tar.bz2
rails-08a4c9979da44654f057494dc76498ed6a8506bc.zip
Remove options from the attributes method, tidy up the implementation. Closes #11093 [juanjo.bazan, Koz]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8863 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rwxr-xr-xactiverecord/lib/active_record/base.rb27
1 files changed, 5 insertions, 22 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index cd33c8891c..94ff704b25 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -2214,35 +2214,18 @@ module ActiveRecord #:nodoc:
# Returns a hash of all the attributes with their names as keys and the values of the attributes as values.
def attributes(options = nil)
- attrs = {}
- self.attribute_names.each do |name|
- attrs[name]=read_attribute(name)
- end
-
- if options.nil?
+ self.attribute_names.inject({}) do |attrs, name|
+ attrs[name] = read_attribute(name)
attrs
- else
- if except = options[:except]
- except = Array(except).collect { |attribute| attribute.to_s }
- except.each { |attribute_name| attrs.delete(attribute_name) }
- attrs
- elsif only = options[:only]
- only = Array(only).collect { |attribute| attribute.to_s }
- attrs.delete_if { |key, value| !only.include?(key) }
- attrs
- else
- raise ArgumentError, "Options does not specify :except or :only (#{options.keys.inspect})"
- end
end
end
# Returns a hash of attributes before typecasting and deserialization.
def attributes_before_type_cast
- attrs = {}
- self.attribute_names.each do |name|
- attrs[name]=read_attribute_before_type_cast(name)
+ self.attribute_names.inject({}) do |attrs, name|
+ attrs[name] = read_attribute_before_typecast(name)
+ attrs
end
- attrs
end
# Format attributes nicely for inspect.