From 7e3cacdb0ecde219278c8297395b4f0f2d67ad2a Mon Sep 17 00:00:00 2001 From: Steven Bazyl Date: Wed, 2 Jan 2013 16:13:26 -0800 Subject: [PATCH] Define custom load/dump for serializing API instances --- lib/google/api_client/discovery/api.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/google/api_client/discovery/api.rb b/lib/google/api_client/discovery/api.rb index 68dc2cfa0..4c58d7e10 100644 --- a/lib/google/api_client/discovery/api.rb +++ b/lib/google/api_client/discovery/api.rb @@ -14,7 +14,7 @@ require 'addressable/uri' - +require 'multi_json' require 'google/inflection' require 'google/api_client/discovery/resource' require 'google/api_client/discovery/method' @@ -281,6 +281,20 @@ module Google "#<%s:%#0x ID:%s>", self.class.to_s, self.object_id, self.id ) end + + ## + # Marshalling support - serialize the API to a string (doc base + original + # discovery document). + def _dump(level) + MultiJson.dump([@document_base.to_s, @discovery_document]) + end + + ## + # Marshalling support - Restore an API instance from serialized form + def self._load(obj) + new(*MultiJson.load(obj)) + end + end end end