Class: Sponge::Auth
- Inherits:
-
Object
- Object
- Sponge::Auth
- Defined in:
- lib/sponge/auth.rb
Instance Method Summary collapse
-
#clear ⇒ Object
Log all users out.
-
#count ⇒ Object
How many users we have logged in.
-
#initialize(client, users) ⇒ Auth
constructor
A new instance of Auth.
-
#logged_in?(user) ⇒ Boolean
Check if a user is logged in.
-
#login(user, pass) ⇒ Object
Log a user in, returns the user if the user has successfully logged in, and nil otherwise.
-
#logout(user) ⇒ Object
Log a user out, returns nil if the user isn’t logged in.
Constructor Details
#initialize(client, users) ⇒ Auth
Returns a new instance of Auth.
4 5 6 7 8 |
# File 'lib/sponge/auth.rb', line 4 def initialize(client, users) @client = client @users = users @logged = [] end |
Instance Method Details
#clear ⇒ Object
Log all users out
36 37 38 |
# File 'lib/sponge/auth.rb', line 36 def clear @logged.clear end |
#count ⇒ Object
How many users we have logged in
31 32 33 |
# File 'lib/sponge/auth.rb', line 31 def count @logged.size end |
#logged_in?(user) ⇒ Boolean
Check if a user is logged in
26 27 28 |
# File 'lib/sponge/auth.rb', line 26 def logged_in?(user) @logged.include?(user) end |
#login(user, pass) ⇒ Object
Log a user in, returns the user if the user has successfully logged in, and nil otherwise
12 13 14 15 16 |
# File 'lib/sponge/auth.rb', line 12 def login(user, pass) return unless @users.key?(user) && @users[user] == pass @logged.push(user).uniq! user end |
#logout(user) ⇒ Object
Log a user out, returns nil if the user isn’t logged in
19 20 21 22 23 |
# File 'lib/sponge/auth.rb', line 19 def logout(user) return unless logged_in?(user) @logged.delete(user) true end |