Class: Reactor::Session
- Inherits:
-
Object
show all
- Includes:
- Observable
- Defined in:
- lib/reactor/session.rb,
lib/reactor/session/user.rb,
lib/reactor/session/observers.rb
Defined Under Namespace
Modules: Observers
Classes: State, User
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(state = State.new) ⇒ Session
Returns a new instance of Session.
20
21
22
|
# File 'lib/reactor/session.rb', line 20
def initialize(state = State.new)
initialize_and_notify(state)
end
|
Class Method Details
.for(user_name) ⇒ Object
36
37
38
|
# File 'lib/reactor/session.rb', line 36
def self.for(user_name)
new(State.new(user_name, nil))
end
|
Instance Method Details
#destroy ⇒ Object
44
45
46
|
# File 'lib/reactor/session.rb', line 44
def destroy
self.session_id = self.user_name = nil
end
|
#logged_in?(session_id) ⇒ Boolean
48
49
50
|
# File 'lib/reactor/session.rb', line 48
def logged_in?(session_id)
self.session_id.present? && user? && self.session_id == session_id
end
|
#login(session_id) ⇒ Object
40
41
42
|
# File 'lib/reactor/session.rb', line 40
def login(session_id)
self.user_name = authenticate(session_id) unless logged_in?(session_id)
end
|
#marshal_dump ⇒ Object
65
66
67
|
# File 'lib/reactor/session.rb', line 65
def marshal_dump
state.serialize
end
|
#marshal_load(array) ⇒ Object
69
70
71
|
# File 'lib/reactor/session.rb', line 69
def marshal_load(array)
initialize_and_notify(State.deserialize(array))
end
|
#session_id ⇒ Object
28
29
30
|
# File 'lib/reactor/session.rb', line 28
def session_id
state.session_id
end
|
#user? ⇒ Boolean
52
53
54
|
# File 'lib/reactor/session.rb', line 52
def user?
user_name.present?
end
|
#user_name ⇒ Object
24
25
26
|
# File 'lib/reactor/session.rb', line 24
def user_name
state.user_name
end
|
#user_name=(new_user_name) ⇒ Object
60
61
62
63
|
# File 'lib/reactor/session.rb', line 60
def user_name=(new_user_name)
state.user_name = new_user_name
proper_notify_observers(new_user_name, true)
end
|