ActiveRecord::AttributeMethods::Read
No documentation available for this module.
Constants
ATTRIBUTE_TYPES_CACHED_BY_DEFAULT = [:datetime, :timestamp, :time, :date]
ReaderMethodCache = Class.new(AttributeMethodCache) {\nprivate\n# We want to generate the methods via module_eval rather than\n# define_method, because define_method is slower on dispatch.\n# Evaluating many similar methods may use more memory as the instruction\n# sequences are duplicated and cached (in MRI). define_method may\n# be slower on dispatch, but if you're careful about the closure\n# created, then define_method will consume much less memory.\n#\n# But sometimes the database might return columns with\n# characters that are not allowed in normal method names (like\n# 'my_column(omg)'. So to work around this we first define with\n# the __temp__ identifier, and then use alias method to rename\n# it to what we want.\n#\n# We are also defining a constant to hold the frozen string of\n# the attribute name. Using a constant means that we do not have\n# to allocate an object on each call to the attribute method.\n# Making it frozen means that it doesn't get duped when used to\n# key the @attributes_cache in read_attribute.\ndef method_body(method_name, const_name)\n<<-EOMETHOD\ndef #{method_name}\nname = ::ActiveRecord::AttributeMethods::AttrNames::ATTR_#{const_name}\nread_attribute(name) { |n| missing_attribute(n, caller) }\nend\nEOMETHOD\nend\n}.new
Files
- activerecord/lib/active_record/attribute_methods/read.rb