method
reader_method
v2.0.3 -
Show latest stable
- Class:
ActiveRecord::Aggregations::ClassMethods
reader_method(name, class_name, mapping, allow_nil)private
No documentation available.
# File activerecord/lib/active_record/aggregations.rb, line 151
def reader_method(name, class_name, mapping, allow_nil)
module_eval do
define_method(name) do |*args|
force_reload = args.first || false
if (instance_variable_get("@#{name}").nil? || force_reload) && (!allow_nil || mapping.any? {|pair| !read_attribute(pair.first).nil? })
instance_variable_set("@#{name}", class_name.constantize.new(*mapping.collect {|pair| read_attribute(pair.first)}))
end
return instance_variable_get("@#{name}")
end
end
end