Skip to content

Instantly share code, notes, and snippets.

@henrik
Created March 28, 2013 06:31
Show Gist options
  • Save henrik/5261139 to your computer and use it in GitHub Desktop.
Save henrik/5261139 to your computer and use it in GitHub Desktop.
# 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