Created
April 23, 2015 18:38
-
-
Save mayfer/6e912dc2088378549a9a to your computer and use it in GitHub Desktop.
Mock implementation of sessions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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