In Ruby on Rails, what kind of design pattern is to use false to denote don't do DB look up and nil to denote ok to look up? -


in restful authentication, found current_user quite intricate that, when @current_user set false, means don't try find user again (usually db), while nil means that's ok, can again in db:

line 8 of lib/authenticated_system.rb

def current_user   @current_user ||= (login_from_session                        || login_from_basic_auth                        || login_from_cookie) unless @current_user == false end 

the intricate thing is, if tries db login_from_session, etc, , can't find it, final value gets assigned @current_user nil, , method returns nil (which last evaluated value in method). unless there 2 other places in code elsewhere can set @current_user false, , trigger unless, causing whole statement return nil, while @current_user remains false, , method returns nil...

i speechless code rely on these intricate facts. false has special meaning, , nil has special meaning in code, not documented, not commented, , current_user can nil, while @current_user can continue false. design pattern, people familiar , know well?

restfulauthentication considered quite old , nasty @ point in rails history, partly because of code pointing out.

i think people advise go more modern authentication solution such devise or authlogic.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -