Class: VCR::Cassette::Serializers

Inherits:
Object
  • Object
show all
Defined in:
lib/vcr/cassette/serializers.rb,
lib/vcr/cassette/serializers/json.rb,
lib/vcr/cassette/serializers/syck.rb,
lib/vcr/cassette/serializers/yaml.rb,
lib/vcr/cassette/serializers/psych.rb

Overview

Keeps track of the cassette serializers in a hash-like object.

Defined Under Namespace

Modules: JSON, Psych, Syck, YAML

Instance Method Summary collapse

Constructor Details

#initializeSerializers

Returns a new instance of Serializers.



11
12
13
# File 'lib/vcr/cassette/serializers.rb', line 11

def initialize
  @serializers = {}
end

Instance Method Details

#[](name) ⇒ Object

Gets the named serializer.

Parameters:

  • name (Symbol)

    the name of the serializer

Returns:

  • the named serializer

Raises:

  • (ArgumentError)

    if there is not a serializer for the given name



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/vcr/cassette/serializers.rb', line 20

def [](name)
  @serializers.fetch(name) do |_|
    @serializers[name] = case name
      when :yaml  then YAML
      when :syck  then Syck
      when :psych then Psych
      when :json  then JSON
      else raise ArgumentError.new("The requested VCR cassette serializer (#{name.inspect}) is not registered.")
    end
  end
end

#[]=(name, value) ⇒ Object

Registers a serializer.

Parameters:

  • name (Symbol)

    the name of the serializer

  • value (#file_extension, #serialize, #deserialize)

    the serializer object. It must implement ‘file_extension()`, `serialize(Hash)` and `deserialize(String)`.



37
38
39
40
41
42
43
# File 'lib/vcr/cassette/serializers.rb', line 37

def []=(name, value)
  if @serializers.has_key?(name)
    warn "WARNING: There is already a VCR cassette serializer registered for #{name.inspect}. Overriding it."
  end

  @serializers[name] = value
end