Skip to content

Instantly share code, notes, and snippets.

@mayfer
Created April 23, 2015 18:38
Show Gist options
  • Save mayfer/6e912dc2088378549a9a to your computer and use it in GitHub Desktop.
Save mayfer/6e912dc2088378549a9a to your computer and use it in GitHub Desktop.
Mock implementation of sessions
class Session
def [](key)
cookie = request.cookies["rack.session"]
output = decrypt(cookie)
return output["user_id"]
end
def []=(key, value)
cookie = request.cookies["rack.session"]
output = decrypt(cookie)
output[key] = value
encrypted = encrypt(output)
request.set_cookie("rack.session", encrypted, expires bla bla)
return value
end
end
sess = Session.new
sess["key"] = "hello"
puts sess["key"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment