1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/core/json.rb

35 lines
657 B
Ruby
Raw Normal View History

2012-04-25 10:31:28 -04:00
require 'multi_json'
module Fog
module JSON
def self.sanitize(data)
case data
when Array
data.map {|datum| sanitize(datum)}
when Hash
for key, value in data
data[key] = sanitize(value)
end
when ::Time
data.strftime("%Y-%m-%dT%H:%M:%SZ")
else
data
end
end
2012-04-25 10:31:28 -04:00
# Do the MultiJson introspection at this level so we can define our encode/decode methods and perform
# the introspection only once rather than once per call.
def self.encode(obj)
MultiJson.encode(obj)
2012-04-25 10:31:28 -04:00
end
def self.decode(obj)
MultiJson.decode(obj)
2012-04-25 10:31:28 -04:00
end
end
end