lib/sax-machine/sax_document.rb in astro-sax-machine-0.0.14 vs lib/sax-machine/sax_document.rb in astro-sax-machine-0.0.15
- old
+ new
@@ -37,11 +37,11 @@
# we only want to insert the getter and setter if they haven't defined it from elsewhere.
# this is how we allow custom parsing behavior. So you could define the setter
# and have it parse the string into a date or whatever.
attr_reader options[:as] unless instance_methods.include?(options[:as].to_s)
- attr_writer options[:as] unless instance_methods.include?("#{options[:as]}=")
+ attr_writer_once options[:as] unless instance_methods.include?("#{options[:as]}=")
end
def columns
sax_config.top_level_elements
end
@@ -86,9 +86,17 @@
attr_writer options[:as] unless instance_methods.include?("#{options[:as]}=")
end
def sax_config
@sax_config ||= SAXConfig.new
+ end
+
+ def attr_writer_once(attr)
+ class_eval <<-SRC
+ def #{attr}=(val)
+ @#{attr} ||= val
+ end
+ SRC
end
end
end