Class: ResponseMate::Tape
- Inherits:
-
Object
- Object
- ResponseMate::Tape
- Defined in:
- lib/response_mate/tape.rb
Overview
Responsible for the recorded responses as files
Class Method Summary collapse
Instance Method Summary collapse
-
#write(key, request, response, meta = {}, output_dir = nil) ⇒ Object
Writes the tape as a file.
Class Method Details
.load(key) ⇒ Object
46 47 48 49 |
# File 'lib/response_mate/tape.rb', line 46 def load(key) YAML.load_file(File.join(ResponseMate.configuration.output_dir, "#{key}.yml")). symbolize_keys end |
Instance Method Details
#write(key, request, response, meta = {}, output_dir = nil) ⇒ Object
Writes the tape as a file
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/response_mate/tape.rb', line 4 def write(key, request, response, = {}, output_dir = nil) # rubocop:disable Metrics/AbcSize output_dir ||= ResponseMate.configuration.output_dir output_path = File.join output_dir, "#{key}.yml" File.open(output_path, 'w') do |f| file_content = { request: request.to_hash.select { |_, v| !v.nil? }, response: { status: response.status, headers: _utf8_encode(response.headers.to_hash), body: _utf8_encode(response.body) }, created_at: Time.now } file_content.merge!(meta: ) if .present? f << file_content.to_yaml end rescue Errno::ENOENT raise ResponseMate::OutputDirError.new(output_dir) end |