Class: MadChatter::Users
- Inherits:
-
Object
- Object
- MadChatter::Users
- Defined in:
- lib/mad_chatter/users.rb
Instance Method Summary collapse
- #add(token, username = nil) ⇒ Object
- #current ⇒ Object
- #find_username_by_token(token) ⇒ Object
-
#initialize ⇒ Users
constructor
A new instance of Users.
- #remove(token) ⇒ Object
- #to_json ⇒ Object
- #token_exists?(token) ⇒ Boolean
- #update(token, username) ⇒ Object
Constructor Details
#initialize ⇒ Users
Returns a new instance of Users.
4 5 6 |
# File 'lib/mad_chatter/users.rb', line 4 def initialize @users = {} end |
Instance Method Details
#add(token, username = nil) ⇒ Object
8 9 10 |
# File 'lib/mad_chatter/users.rb', line 8 def add(token, username = nil) @users[token] = username end |
#current ⇒ Object
24 25 26 |
# File 'lib/mad_chatter/users.rb', line 24 def current @users.values end |
#find_username_by_token(token) ⇒ Object
20 21 22 |
# File 'lib/mad_chatter/users.rb', line 20 def find_username_by_token(token) @users[token] end |
#remove(token) ⇒ Object
16 17 18 |
# File 'lib/mad_chatter/users.rb', line 16 def remove(token) @users.delete(token) end |
#to_json ⇒ Object
32 33 34 35 36 37 |
# File 'lib/mad_chatter/users.rb', line 32 def to_json JSON.generate({ type: 'users', json: current, }) end |
#token_exists?(token) ⇒ Boolean
28 29 30 |
# File 'lib/mad_chatter/users.rb', line 28 def token_exists?(token) @users[token].exists? end |
#update(token, username) ⇒ Object
12 13 14 |
# File 'lib/mad_chatter/users.rb', line 12 def update(token, username) @users[token] = username end |