Module: VCR::Cassette::Serializers::Psych

Extended by:
EncodingErrorHandling, Psych, VCR::Cassette::SyntaxErrorHandling
Included in:
Psych
Defined in:
lib/vcr/cassette/serializers/psych.rb

Overview

The Psych serializer. Psych is the new YAML engine in ruby 1.9.

See Also:

Constant Summary collapse

ENCODING_ERRORS =
[ArgumentError]
SYNTAX_ERRORS =
[::Psych::SyntaxError]

Instance Method Summary collapse

Methods included from EncodingErrorHandling

handle_encoding_errors

Methods included from VCR::Cassette::SyntaxErrorHandling

handle_syntax_errors

Instance Method Details

#deserialize(string) ⇒ Hash

Deserializes the given string using Psych.

Parameters:

  • string (String)

    the YAML string

Returns:

  • (Hash)

    the deserialized object



45
46
47
48
49
50
51
# File 'lib/vcr/cassette/serializers/psych.rb', line 45

def deserialize(string)
  handle_encoding_errors do
    handle_syntax_errors do
      ::Psych.load(string)
    end
  end
end

#file_extensionString

The file extension to use for this serializer.

Returns:

  • (String)

    “yml”



25
26
27
# File 'lib/vcr/cassette/serializers/psych.rb', line 25

def file_extension
  "yml"
end

#serialize(hash) ⇒ String

Serializes the given hash using Psych.

Parameters:

  • hash (Hash)

    the object to serialize

Returns:

  • (String)

    the YAML string



33
34
35
36
37
38
39
# File 'lib/vcr/cassette/serializers/psych.rb', line 33

def serialize(hash)
  handle_encoding_errors do
    result = ::Psych.dump(hash)
    result.gsub!(": \n", ": null\n") # set canonical null value in order to avoid trailing whitespaces
    result
  end
end