aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attributes.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2009-10-19 12:33:36 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2009-10-19 12:33:36 -0700
commita49c3b03650b3193cc9440a3b219ab7f19326297 (patch)
treedd68d637a074bc08d1328d780aeb092b2a4c8874 /activerecord/lib/active_record/attributes.rb
parent028911ad00e7f7733064a80393a1548401bba7af (diff)
parent1ac5cf478825391071d34ec3d7f294fe28c0fceb (diff)
downloadrails-a49c3b03650b3193cc9440a3b219ab7f19326297.tar.gz
rails-a49c3b03650b3193cc9440a3b219ab7f19326297.tar.bz2
rails-a49c3b03650b3193cc9440a3b219ab7f19326297.zip
Merge branch 'master' of github.com:rails/rails
Diffstat (limited to 'activerecord/lib/active_record/attributes.rb')
-rw-r--r--activerecord/lib/active_record/attributes.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/attributes.rb b/activerecord/lib/active_record/attributes.rb
new file mode 100644
index 0000000000..e4d9e89821
--- /dev/null
+++ b/activerecord/lib/active_record/attributes.rb
@@ -0,0 +1,37 @@
+module ActiveRecord
+ module Attributes
+
+ # Returns true if the given attribute is in the attributes hash
+ def has_attribute?(attr_name)
+ _attributes.key?(attr_name)
+ end
+
+ # Returns an array of names for the attributes available on this object sorted alphabetically.
+ def attribute_names
+ _attributes.keys.sort!
+ end
+
+ # Returns a hash of all the attributes with their names as keys and the values of the attributes as values.
+ def attributes
+ attributes = _attributes.dup
+ attributes.typecast! unless _attributes.frozen?
+ attributes.to_h
+ end
+
+ protected
+
+ # Not to be confused with the public #attributes method, which returns a typecasted Hash.
+ def _attributes
+ @attributes
+ end
+
+ def initialize_attribute_store(merge_attributes = nil)
+ @attributes = ActiveRecord::Attributes::Store.new
+ @attributes.merge!(merge_attributes) if merge_attributes
+ @attributes.types.merge!(self.class.attribute_types)
+ @attributes.aliases.merge!('id' => self.class.primary_key) unless 'id' == self.class.primary_key
+ @attributes
+ end
+
+ end
+end