Module: RackSessionManipulation::JSONEncoder

Defined in:
lib/rack_session_manipulation/json_encoder.rb

Overview

The stock encoder for session data. Encodes and decodes everything to/from JSON payloads.

Class Method Summary collapse

Class Method Details

.decode(encoded_data) ⇒ Hash

Decoder for session state into a standard Ruby hash using JSON.

Parameters:

  • encoded_data (String)

    JSON encoded session data

Returns:

  • (Hash)

    Hash version of the session data



11
12
13
# File 'lib/rack_session_manipulation/json_encoder.rb', line 11

def decode(encoded_data)
  JSON.parse(encoded_data)
end

.encode(obj) ⇒ String

Encoder for session state using JSON.

Parameters:

  • obj (Hash)

    An object that can be serialized using JSON, generally this is a hash.

Returns:

  • (String)

    The encoded data.



20
21
22
# File 'lib/rack_session_manipulation/json_encoder.rb', line 20

def encode(obj)
  JSON.generate(obj)
end