Thanks for your response and support, Dreamcat I really appreciate your perspective here, especially because your uses for to_xml are more demanding than my own.
Like you, I feel like there’s more work that could be done on ActiveRecord::Serialization. In particular, I was surprised to find that to_json doesn’t support the same variety of options that to_xml does: there’s no :procs option and no optional block supported in to_json. Extending these options to to_json would be especially pertinent to me now, since in the last few months, I’ve (IMHO) upgraded my data interchange format from XML to JSON. On that note, future data interchange formats are sure to appear, and support is sure to be sought after; and wouldn’t it be nice if ActiveRecord::Serialization was prepared to offer a consistent interface (within reason) for serializing Records into NFIF (new-fangled interchange format)? I’m thinking of something that would pair well with respond_to. (Is anyone working on this? Is there interest in me taking a swing at it? If there is, I’ll try to schedule some time.) As it is now, I just convert my ActiveRecord instances into a custom hash and to_json that… Lame!
But yes, this patch definitely doesn’t try to do all that. What it does do is take advantage of what’s already been built out for to_xml and enable more lazy evaluation. As it is now, the :procs option is essentially rendered impotent when serializing arrays of Records, because it can’t easily address the Record being serializing. But this was probably just an oversight. When implementing the :procs option, I imagine the originator simply didn’t consider the possibility that arrays would be serialized – that is, they only considered the scenario in which a single Record was being serialized – and a single Record would be easily captured and addressed from a proc’s closure.
So, yes, this patch is VERY slight. It simply increases the supported arity of procs passed into to_xml’s :procs option from 1 to 2, the second of which becomes the ActiveRecord instance being serialized. But despite the patch’s simplicity, this improvement makes the :procs option sooo much more powerful… and lazier So taking to_xml for granted, this seems to be a great starting point for improvements.
Here, let me “lazy-evaluate” the patch for everybody
@@ -215,7 +226,7 @@ module ActiveRecord #:nodoc:
if procs = options.delete(:procs)
[ *procs ].each do |proc|
Thanks for your time