Sha256: c7f28147ae3fb931d526514c9bb27481c933fb61cfab242ff86ae50767806bef

Contents?: true

Size: 1.05 KB

Versions: 18

Compression:

Stored size: 1.05 KB

Contents

require "multi_json"

module Fog

  # @note Extracting JSON components out of core is a work in progress.
  #
  # The {JSON} module includes functionality that is common between APIs using
  # JSON to send and receive data.
  #
  # The intent is to provide common code for provider APIs using JSON but not
  # require it for those using XML.
  #
  # @todo Add +require "fog/json" and/or +include Fog::JSON+ to providers using
  #   its services
  #
  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

    # 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)
    end

    def self.decode(obj)
      MultiJson.decode(obj)
    end
  end
end

Version data entries

18 entries across 18 versions & 3 rubygems

Version Path
fog-maestrodev-1.18.0.20131121075022 lib/fog/json.rb
fog-maestrodev-1.18.0.20131118164830 lib/fog/json.rb
fog-maestrodev-1.18.0.20131115184302 lib/fog/json.rb
fog-maestrodev-1.18.0.20131114200144 lib/fog/json.rb
gapinc-fog-1.12.1.2.1 lib/fog/json.rb
fog-maestrodev-1.18.0.20131112185232 lib/fog/json.rb
fog-maestrodev-1.18.0.20131111203459 lib/fog/json.rb
fog-1.18.0 lib/fog/json.rb
fog-1.17.0 lib/fog/json.rb
fog-1.16.0 lib/fog/json.rb
fog-maestrodev-1.15.0.20130927082724 lib/fog/json.rb
fog-maestrodev-1.15.0.20130829165835 lib/fog/json.rb
fog-1.15.0 lib/fog/json.rb
gapinc-fog-1.14.0 lib/fog/json.rb
fog-maestrodev-1.14.0.20130806165225 lib/fog/json.rb
fog-1.14.0 lib/fog/json.rb
fog-1.13.0 lib/fog/json.rb
gapinc-fog-1.12.1.2 lib/fog/json.rb