Created
March 28, 2013 06:31
-
-
Save henrik/5261139 to your computer and use it in GitHub Desktop.
A precursor of http://github.com/henrik/autho.
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
# https://github.com/barsoom/attr_extras | |
require "attr_extras" | |
class UserSession | |
pattr_initialize :controller, :session_key, :finder | |
# NOTE: Not memoized yet. | |
def user | |
if id | |
finder.find(id) | |
else | |
nil | |
end | |
end | |
def user=(user) | |
controller.session[session_key] = user.id | |
end | |
def clear | |
controller.session[session_key] = nil | |
end | |
private | |
def id | |
controller.session[session_key] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment