Module: VCR::Cassette::Serializers::YAML
- Extended by:
- EncodingErrorHandling, YAML, VCR::Cassette::SyntaxErrorHandling
- Included in:
- YAML
- Defined in:
- lib/vcr/cassette/serializers/yaml.rb
Overview
The YAML serializer. This will use either Psych or Syck, which ever your ruby interpreter defaults to. You can also force VCR to use Psych or Syck by using one of those serializers.
Constant Summary collapse
- ENCODING_ERRORS =
[ArgumentError]
- SYNTAX_ERRORS =
[::Psych::SyntaxError]
Instance Method Summary collapse
-
#deserialize(string) ⇒ Hash
Deserializes the given string using YAML.
-
#file_extension ⇒ String
The file extension to use for this serializer.
-
#serialize(hash) ⇒ String
Serializes the given hash using YAML.
Methods included from EncodingErrorHandling
Methods included from VCR::Cassette::SyntaxErrorHandling
Instance Method Details
#deserialize(string) ⇒ Hash
Deserializes the given string using YAML.
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/vcr/cassette/serializers/yaml.rb', line 47 def deserialize(string) handle_encoding_errors do handle_syntax_errors do if ::YAML.respond_to?(:unsafe_load) ::YAML.unsafe_load(string) else ::YAML.load(string) end end end end |
#file_extension ⇒ String
The file extension to use for this serializer.
27 28 29 |
# File 'lib/vcr/cassette/serializers/yaml.rb', line 27 def file_extension "yml" end |
#serialize(hash) ⇒ String
Serializes the given hash using YAML.
35 36 37 38 39 40 41 |
# File 'lib/vcr/cassette/serializers/yaml.rb', line 35 def serialize(hash) handle_encoding_errors do result = ::YAML.dump(hash) result.gsub!(": \n", ": null\n") # set canonical null value in order to avoid trailing whitespaces result end end |