1
0
Fork 0

Null object pattern for User as GuestUser

This commit is contained in:
Andrew Tomaka 2015-10-08 18:03:09 -04:00
parent d9bea7f39a
commit 92dbf98339
2 changed files with 12 additions and 1 deletions

View file

@ -10,9 +10,10 @@ class ApplicationController < ActionController::Base
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
@current_user ||= GuestUser.new
end
def logged_in?
@logged_in ||= !!current_user
@logged_in ||= current_user.class.name.demodulize == 'User'
end
end

View file

@ -26,3 +26,13 @@ class User < ActiveRecord::Base
self.add_role :admin
end
end
class GuestUser
def admin?
false
end
def moderator?
false
end
end