Class: Clearance::Session
- Inherits:
-
Object
- Object
- Clearance::Session
- Defined in:
- lib/clearance/session.rb
Instance Method Summary collapse
- #add_cookie_to_headers(headers) ⇒ Object
- #current_user ⇒ Object
-
#initialize(env) ⇒ Session
constructor
A new instance of Session.
- #sign_in(user, &block) ⇒ Object
- #sign_out ⇒ Object
- #signed_in? ⇒ Boolean
- #signed_out? ⇒ Boolean
Constructor Details
#initialize(env) ⇒ Session
Returns a new instance of Session.
5 6 7 8 9 |
# File 'lib/clearance/session.rb', line 5 def initialize(env) @env = env @current_user = nil @cookies = nil end |
Instance Method Details
#add_cookie_to_headers(headers) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/clearance/session.rb', line 11 def (headers) if [:value].present? Rack::Utils.( headers, , ) end end |
#current_user ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/clearance/session.rb', line 21 def current_user if remember_token.present? @current_user ||= user_from_remember_token(remember_token) end @current_user end |
#sign_in(user, &block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/clearance/session.rb', line 29 def sign_in(user, &block) @current_user = user status = run_sign_in_stack if status.success? [] = user && user.remember_token else @current_user = nil end if block_given? block.call(status) end end |
#sign_out ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/clearance/session.rb', line 44 def sign_out if signed_in? current_user.reset_remember_token! end @current_user = nil .delete end |
#signed_in? ⇒ Boolean
53 54 55 |
# File 'lib/clearance/session.rb', line 53 def signed_in? current_user.present? end |
#signed_out? ⇒ Boolean
57 58 59 |
# File 'lib/clearance/session.rb', line 57 def signed_out? ! signed_in? end |