instance method
reader_method
Ruby on Rails 6.1.7.10
Since v2.2.3 PrivateSignature
reader_method(name, class_name, mapping, allow_nil, constructor)
No documentation comment.
Parameters
-
namereq -
class_namereq -
mappingreq -
allow_nilreq -
constructorreq
Source
# File activerecord/lib/active_record/aggregations.rb, line 245
def reader_method(name, class_name, mapping, allow_nil, constructor)
define_method(name) do
if @aggregation_cache[name].nil? && (!allow_nil || mapping.any? { |key, _| !read_attribute(key).nil? })
attrs = mapping.collect { |key, _| read_attribute(key) }
object = constructor.respond_to?(:call) ?
constructor.call(*attrs) :
class_name.constantize.send(constructor, *attrs)
@aggregation_cache[name] = object
end
@aggregation_cache[name]
end
end
Defined in activerecord/lib/active_record/aggregations.rb line 245
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Aggregations::ClassMethods