module VCR::Cassette::Persisters::FileSystem
def [](file_name)
-
(String)
- the cassette content
Parameters:
-
file_name
(String
) -- the file name
def [](file_name) path = absolute_path_to_file(file_name) return nil unless File.exist?(path) File.binread(path) end
def []=(file_name, content)
-
content
(String
) -- the content to store -
file_name
(String
) -- the file name
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
def absolute_path_for(path)
def absolute_path_for(path) Dir.chdir(path) { Dir.pwd } end
def absolute_path_to_file(file_name)
- Private: -
def absolute_path_to_file(file_name) return nil unless storage_location File.join(storage_location, sanitized_file_name_from(file_name)) end
def downcase_cassette_names?
def downcase_cassette_names? !!VCR.configuration .default_cassette_options .dig(:persister_options, :downcase_cassette_names) end
def sanitized_file_name_from(file_name)
def sanitized_file_name_from(file_name) parts = file_name.to_s.split('.') if parts.size > 1 && !parts.last.include?(File::SEPARATOR) file_extension = '.' + parts.pop end file_name = parts.join('.').gsub(/[^[:word:]\-\/]+/, '_') + file_extension.to_s file_name.downcase! if downcase_cassette_names? file_name end
def storage_location=(dir)
- Private: -
def storage_location=(dir) FileUtils.mkdir_p(dir) if dir @storage_location = dir ? absolute_path_for(dir) : nil end