method
def_classed_elements
def_classed_elements(name, attribute, plural_class_name=nil, plural_name=nil, new_name=nil)
public
Hide source
# File lib/rss/maker/base.rb, line 114 def def_classed_elements(name, attribute, plural_class_name=nil, plural_name=nil, new_name=nil) plural_name ||= "#{name}s" new_name ||= name def_classed_element(plural_name, plural_class_name) local_variable_name = "_#{name}" new_value_variable_name = "new_value" additional_setup_code = nil if block_given? additional_setup_code = yield(local_variable_name, new_value_variable_name) end module_eval("def \#{name}\n\#{local_variable_name} = \#{plural_name}.first\n\#{local_variable_name} ? \#{local_variable_name}.\#{attribute} : nil\nend\n\ndef \#{name}=(\#{new_value_variable_name})\n\#{local_variable_name} =\n\#{plural_name}.first || \#{plural_name}.new_\#{new_name}\n\#{additional_setup_code}\n\#{local_variable_name}.\#{attribute} = \#{new_value_variable_name}\nend\n", __FILE__, __LINE__ + 1) end