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,
lib/vcr/cassette/serializers/compressed.rb

Overview

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

Defined Under Namespace

Modules: Compressed, JSON, Psych, Syck, YAML

Instance Method Summary collapse

Constructor Details

#initializeSerializers

Returns a new instance of Serializers.



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

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



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

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
      when :compressed  then Compressed
      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)`.



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

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