Class: Rack::Protection::EncryptedCookie::Base64::JSON

Inherits:
Rack::Protection::EncryptedCookie::Base64 show all
Defined in:
lib/rack/protection/encrypted_cookie.rb

Overview

N.B. Unlike other encoding methods, the contained objects must be a valid JSON composite type, either a Hash or an Array.

Instance Method Summary collapse

Instance Method Details

#decode(str) ⇒ Object



99
100
101
102
103
104
105
106
107
# File 'lib/rack/protection/encrypted_cookie.rb', line 99

def decode(str)
  return unless str

  begin
    ::JSON.parse(super(str))
  rescue StandardError
    nil
  end
end

#encode(obj) ⇒ Object



95
96
97
# File 'lib/rack/protection/encrypted_cookie.rb', line 95

def encode(obj)
  super(::JSON.dump(obj))
end