Class: BooticClient::Client::SafeCacheSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/bootic_client/client.rb

Constant Summary collapse

PREFIX =
'__booticclient__base64__:'.freeze
PREFIX_EXP =
%r{^#{PREFIX}}.freeze

Class Method Summary collapse

Class Method Details

.dump(data) ⇒ Object


68
69
70
71
# File 'lib/bootic_client/client.rb', line 68

def self.dump(data)
  data[:body] = "#{PREFIX}#{Base64.strict_encode64(data[:body])}" if data[:body].is_a?(String)
  JSON.dump(data)
end

.load(string) ⇒ Object


73
74
75
76
77
78
79
# File 'lib/bootic_client/client.rb', line 73

def self.load(string)
  data = JSON.load(string)
  if data['body'] =~ PREFIX_EXP
    data['body'] = Base64.strict_decode64(data['body'].sub(PREFIX, ''))
  end
  data
end