Methods
Instance Public methods
Returns true
if the provided attribute is being cached.
Source: show
# File activerecord/lib/active_record/attribute_methods/read.rb, line 33 def cache_attribute?(attr_name) cached_attributes.include?(attr_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
).
Source: show
# File activerecord/lib/active_record/attribute_methods/read.rb, line 22 def cache_attributes(*attribute_names) cached_attributes.merge attribute_names.map { |attr| attr.to_s } end
Returns the attributes which are cached. By default time related columns
with datatype :datetime, :timestamp, :time, :date
are cached.
Source: show
# File activerecord/lib/active_record/attribute_methods/read.rb, line 28 def cached_attributes @cached_attributes ||= columns.select { |c| cacheable_column?(c) }.map { |col| col.name }.to_set end
Instance Protected methods
Source: show
# File activerecord/lib/active_record/attribute_methods/read.rb, line 38 def define_method_attribute(attr_name) if serialized_attributes.include?(attr_name) define_read_method_for_serialized_attribute(attr_name) else define_read_method(attr_name, attr_name, columns_hash[attr_name]) end if attr_name == primary_key && attr_name != "id" define_read_method('id', attr_name, columns_hash[attr_name]) end end