Class: Workato::Testing::VCREncryptedCassetteSerializer

Inherits:
ActiveSupport::EncryptedFile
  • Object
show all
Defined in:
lib/workato/testing/vcr_encrypted_cassette_serializer.rb

Instance Method Summary collapse

Constructor Details

#initializeVCREncryptedCassetteSerializer

Returns a new instance of VCREncryptedCassetteSerializer.



9
10
11
12
13
14
15
16
# File 'lib/workato/testing/vcr_encrypted_cassette_serializer.rb', line 9

def initialize
  super(
    content_path: '',
    key_path: Workato::Connector::Sdk::DEFAULT_MASTER_KEY_PATH,
    env_key: Workato::Connector::Sdk::DEFAULT_MASTER_KEY_ENV,
    raise_if_missing_key: true
  )
end

Instance Method Details

#deserialize(string) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/workato/testing/vcr_encrypted_cassette_serializer.rb', line 33

def deserialize(string)
  ::Dir::Tmpname.create('vcr_cassette') do |tmp_path|
    @content_path = Pathname.new(tmp_path)
  end
  File.write(@content_path, string)
  ::YAML.safe_load(read).presence || {}
ensure
  File.unlink(content_path) if content_path.exist?
  @content_path = ''
end

#file_extensionObject



18
19
20
# File 'lib/workato/testing/vcr_encrypted_cassette_serializer.rb', line 18

def file_extension
  'enc'
end

#serialize(hash) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/workato/testing/vcr_encrypted_cassette_serializer.rb', line 22

def serialize(hash)
  ::Dir::Tmpname.create('vcr_cassette') do |tmp_path|
    @content_path = Pathname.new(tmp_path)
  end
  write(YAML.dump(hash))
  File.binread(content_path)
ensure
  File.unlink(content_path) if content_path.exist?
  @content_path = ''
end