[LRUG] Serialising a struct

Stephen Nelson-Smith sanelson at gmail.com
Mon Apr 14 07:50:39 PDT 2014


On Mon, Apr 14, 2014 at 3:41 PM, Matt Spendlove <matt at cenatus.org> wrote:

> I'm not sure why replaying responses via VCR doesn't help you but assuming
> you don't want to do that, the simplest thing you can do is just new up
> some Structs that mirror the data. Are the responses really that verbose?

VCR gives me an XML payload.  I want a struct that I can operate on.  I had
a poke into the aws-sdk-core code to see if there was a place where I could
inject the XML and get the Struct out, but it didn't look hopeful.

The responses aren't TOO verbose, and for canned data purposes I don't need
that many... but it just felt like there ought to be a way to do it
automatically.  I'm currently thinking something like (untested,

images = ec2.describe_images(owners: ['self']).images.map(&:to_h)
serialised_images = images.to_json
MyEc2Struct = Struct.new(images.keys)
canned_images = serialised_images.reduce(MyEc2Struct.new) {|s, kv| s[kv[0]]
= kv[1]; s}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20140414/7ea51f64/attachment-0003.html>

More information about the Chat mailing list