Class: VCR::Cassette::Persisters

Inherits:
Object
  • Object
show all
Defined in:
lib/vcr/cassette/persisters.rb,
lib/vcr/cassette/persisters/file_system.rb

Overview

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

Defined Under Namespace

Modules: FileSystem

Instance Method Summary collapse

Constructor Details

#initializePersisters

Returns a new instance of Persisters.



8
9
10
# File 'lib/vcr/cassette/persisters.rb', line 8

def initialize
  @persisters = {}
end

Instance Method Details

#[](name) ⇒ Object

Gets the named persister.

Parameters:

  • name (Symbol)

    the name of the persister

Returns:

  • the named persister

Raises:

  • (ArgumentError)

    if there is not a persister for the given name



17
18
19
20
21
22
23
24
25
# File 'lib/vcr/cassette/persisters.rb', line 17

def [](name)
  @persisters.fetch(name) do |_|
    @persisters[name] = case name
      when :file_system then FileSystem
      else raise ArgumentError, "The requested VCR cassette persister " +
                                "(#{name.inspect}) is not registered."
    end
  end
end

#[]=(name, value) ⇒ Object

Registers a persister.

Parameters:

  • name (Symbol)

    the name of the persister

  • value (#[], #[]=)

    the persister object. It must implement ‘[]` and `[]=`.



31
32
33
34
35
36
37
38
# File 'lib/vcr/cassette/persisters.rb', line 31

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

  @persisters[name] = value
end