module RackSessionManipulation::JSONEncoder
The stock encoder for session data. Encodes and decodes everything to/from JSON payloads.
Public Class Methods
decode(encoded_data)
click to toggle source
Decoder for session state into a standard Ruby hash using JSON.
@param [String] encoded_data JSON encoded session data @return [Hash] Hash version of the session data
# File lib/rack_session_manipulation/json_encoder.rb, line 11 def decode(encoded_data) JSON.parse(encoded_data) end
encode(obj)
click to toggle source
Encoder for session state using JSON.
@param [Hash] obj An object that can be serialized using JSON,
generally this is a hash.
@return [String] The encoded data.
# File lib/rack_session_manipulation/json_encoder.rb, line 20 def encode(obj) JSON.generate(obj) end