method
define_read_method
rails latest stable - Class:
ActiveRecord::AttributeMethods::ClassMethods
Method deprecated or moved
This method is deprecated or moved on the latest stable version. The last existing version (v2.3.8) is shown here.
define_read_method(symbol, attr_name, column)private
Define an attribute reader method. Cope with nil column.
# File activerecord/lib/active_record/attribute_methods.rb, line 146
def define_read_method(symbol, attr_name, column)
cast_code = column.type_cast_code('v') if column
access_code = cast_code ? "(v=@attributes['#{attr_name}']) && #{cast_code}" : "@attributes['#{attr_name}']"
unless attr_name.to_s == self.primary_key.to_s
access_code = access_code.insert(0, "missing_attribute('#{attr_name}', caller) unless @attributes.has_key?('#{attr_name}'); ")
end
if cache_attribute?(attr_name)
access_code = "@attributes_cache['#{attr_name}'] ||= (#{access_code})"
end
evaluate_attribute_method attr_name, "def #{symbol}; #{access_code}; end"
end Related methods
- Instance methods
- attribute_method_suffix
- cache_attribute?
- cache_attributes
- cached_attributes
- define_attribute_methods
- define_read_methods
- generated_methods
- generated_methods?
- instance_method_already_implemented?
- match_attribute_method?
- Private methods
-
attribute_method_suffixes -
create_time_zone_conversion_attribute? -
define_question_method -
define_read_method -
define_read_method_for_serialized_attribute -
define_read_method_for_time_zone_conversion -
define_write_method -
define_write_method_for_time_zone_conversion -
evaluate_attribute_method -
rebuild_attribute_method_regexp