method
reader_method
v1.2.6 -
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 147
def reader_method(name, class_name, mapping, allow_nil)
mapping = (Array === mapping.first ? mapping : [ mapping ])
allow_nil_condition = if allow_nil
mapping.collect { |pair| "!read_attribute(\"#{pair.first}\").nil?"}.join(" && ")
else
"true"
end
module_eval "def \#{name}(force_reload = false)\nif (@\#{name}.nil? || force_reload) && \#{allow_nil_condition}\n@\#{name} = \#{class_name}.new(\#{mapping.collect { |pair| \"read_attribute(\\\"\#{pair.first}\\\")\"}.join(\", \")})\nend\nreturn @\#{name}\nend\n"
end