Module: VCR::Cassette::Persisters::FileSystem

Extended by:
FileSystem
Included in:
FileSystem
Defined in:
lib/vcr/cassette/persisters/file_system.rb

Overview

The only built-in cassette persister. Persists cassettes to the file system.

Instance Method Summary collapse

Instance Method Details

#[](file_name) ⇒ String

Gets the cassette for the given storage key (file name).

Parameters:

  • file_name (String)

    the file name

Returns:

  • (String)

    the cassette content



23
24
25
26
27
# File 'lib/vcr/cassette/persisters/file_system.rb', line 23

def [](file_name)
  path = absolute_path_to_file(file_name)
  return nil unless File.exist?(path)
  File.binread(path)
end

#[]=(file_name, content) ⇒ Object

Sets the cassette for the given storage key (file name).

Parameters:

  • file_name (String)

    the file name

  • content (String)

    the content to store



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

def []=(file_name, content)
  path = absolute_path_to_file(file_name)
  directory = File.dirname(path)
  FileUtils.mkdir_p(directory) unless File.exist?(directory)
  File.binwrite(path, content)
end