diff options
author | Joshua Peek <josh@joshpeek.com> | 2009-07-29 21:00:46 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-07-30 17:54:00 -0500 |
commit | bd07c5ca8e67c93885d96a24dcf1167d6d503a8c (patch) | |
tree | d48292aee0f081520e98c97055f8713458476a38 /activerecord/lib | |
parent | 94dabf9b4bf14de665cb17570209078f16920e54 (diff) | |
download | rails-bd07c5ca8e67c93885d96a24dcf1167d6d503a8c.tar.gz rails-bd07c5ca8e67c93885d96a24dcf1167d6d503a8c.tar.bz2 rails-bd07c5ca8e67c93885d96a24dcf1167d6d503a8c.zip |
cache_attributes is related to attribute reading
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods.rb | 19 | ||||
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/read.rb | 19 |
2 files changed, 19 insertions, 19 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 9a5d719179..b41c7ffdab 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -87,25 +87,6 @@ module ActiveRecord @_defined_class_methods.include?(method_name) end - # +cache_attributes+ allows you to declare which converted attribute values should - # be cached. Usually caching only pays off for attributes with expensive conversion - # methods, like time related columns (e.g. +created_at+, +updated_at+). - def cache_attributes(*attribute_names) - attribute_names.each {|attr| cached_attributes << attr.to_s} - end - - # Returns the attributes which are cached. By default time related columns - # with datatype <tt>:datetime, :timestamp, :time, :date</tt> are cached. - def cached_attributes - @cached_attributes ||= - columns.select{|c| attribute_types_cached_by_default.include?(c.type)}.map{|col| col.name}.to_set - end - - # Returns +true+ if the provided attribute is being cached. - def cache_attribute?(attr_name) - cached_attributes.include?(attr_name) - end - private # Suffixes a, ?, c become regexp /(a|\?|c)$/ def rebuild_attribute_method_regexp diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb index dda700d04c..5285fda868 100644 --- a/activerecord/lib/active_record/attribute_methods/read.rb +++ b/activerecord/lib/active_record/attribute_methods/read.rb @@ -8,6 +8,25 @@ module ActiveRecord end module ClassMethods + # +cache_attributes+ allows you to declare which converted attribute values should + # be cached. Usually caching only pays off for attributes with expensive conversion + # methods, like time related columns (e.g. +created_at+, +updated_at+). + def cache_attributes(*attribute_names) + attribute_names.each {|attr| cached_attributes << attr.to_s} + end + + # Returns the attributes which are cached. By default time related columns + # with datatype <tt>:datetime, :timestamp, :time, :date</tt> are cached. + def cached_attributes + @cached_attributes ||= + columns.select{|c| attribute_types_cached_by_default.include?(c.type)}.map{|col| col.name}.to_set + end + + # Returns +true+ if the provided attribute is being cached. + def cache_attribute?(attr_name) + cached_attributes.include?(attr_name) + end + protected def define_attribute_method(attr_name) if self.serialized_attributes[attr_name] |