Module: Sinatra::Hellhound::Helpers
- Defined in:
- lib/hellhound.rb
Instance Method Summary collapse
-
#current_user ⇒ Object
Returns the current_user, it’s an instance of
usermodel. -
#get_user(id) ⇒ Object
Returns the user from the database, it can be overwritten to adapat to the other strategies.
-
#logged_in? ⇒ Boolean
Returns true if
current_useris logged and active. -
#logout! ⇒ Object
Returns the user that logged out and remove user from the cache and the session.
-
#refresh_current_user ⇒ Object
Returns the current_user, it’s an instance of
usermodel.
Instance Method Details
#current_user ⇒ Object
Returns the current_user, it’s an instance of user model
18 19 20 21 22 |
# File 'lib/hellhound.rb', line 18 def current_user if session[:user] .hellhound_cache ? CACHE.get("user-#{session[:user]}") : get_user(session[:user]) end end |
#get_user(id) ⇒ Object
Returns the user from the database, it can be overwritten to adapat to the other strategies
11 12 13 |
# File 'lib/hellhound.rb', line 11 def get_user id raise Exception, "You need to override this method" end |
#logged_in? ⇒ Boolean
Returns true if current_user is logged and active.
36 37 38 |
# File 'lib/hellhound.rb', line 36 def logged_in? !! session[:user] end |
#logout! ⇒ Object
Returns the user that logged out and remove user from the cache and the session
44 45 46 47 48 |
# File 'lib/hellhound.rb', line 44 def logout! user = session[:user] session.clear user end |
#refresh_current_user ⇒ Object
Returns the current_user, it’s an instance of user model
27 28 29 30 31 |
# File 'lib/hellhound.rb', line 27 def refresh_current_user if session[:user] CACHE.set("user-#{session[:user]}", get_user(session[:user])) if .hellhound_cache end end |