1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
require 'psych'
module VCR
class Cassette
class Serializers
# The Psych serializer. Psych is the new YAML engine in ruby 1.9.
#
# @see JSON
# @see Syck
# @see YAML
module Psych
extend self
extend EncodingErrorHandling
# @private
ENCODING_ERRORS = [ArgumentError]
# The file extension to use for this serializer.
#
# @return [String] "yml"
def file_extension
"yml"
end
# Serializes the given hash using Psych.
#
# @param [Hash] hash the object to serialize
# @return [String] the YAML string
def serialize(hash)
handle_encoding_errors do
::Psych.dump(hash)
end
end
# Deserializes the given string using Psych.
#
# @param [String] string the YAML string
# @return [Hash] the deserialized object
def deserialize(string)
handle_encoding_errors do
::Psych.load(string)
end
end
end
end
end
end
|