Class: JsonApiSerializer

Inherits:
Object
  • Object
show all
Includes:
VCR::Cassette::EncodingErrorHandling, VCR::Cassette::Serializers::YAML, VCR::Cassette::SyntaxErrorHandling
Defined in:
lib/matic/testing/vcr_json_api/json_api_serializer.rb

Constant Summary collapse

HTTP_INTERACTIONS =
'http_interactions'.freeze
REQUEST =
'request'.freeze
RESPONSE =
'response'.freeze
HEADERS =
'headers'.freeze
BODY =
'body'.freeze
BODY_STRING =
'string'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(format = :json, remove_headers = false) ⇒ JsonApiSerializer

Returns a new instance of JsonApiSerializer.



13
14
15
16
# File 'lib/matic/testing/vcr_json_api/json_api_serializer.rb', line 13

def initialize(format = :json, remove_headers = false)
  @format = format
  @remove_headers = remove_headers
end

Instance Method Details

#deserialize(string) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/matic/testing/vcr_json_api/json_api_serializer.rb', line 29

def deserialize(string)
  data = super(string)
  data[HTTP_INTERACTIONS].each do |interaction|
    deserialize_request_body(interaction)
    deserialize_response_body(interaction)
  end
  data
end

#serialize(hash) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/matic/testing/vcr_json_api/json_api_serializer.rb', line 18

def serialize(hash)
  hash[HTTP_INTERACTIONS].each do |interaction|
    remove_headers(interaction) if @remove_headers

    serialize_request_body(interaction)
    serialize_response_body(interaction)
  end

  super(hash)
end