Class: Yauth::UserManager
- Inherits:
-
Object
- Object
- Yauth::UserManager
- Includes:
- Enumerable
- Defined in:
- lib/yauth/user_manager.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add(user) ⇒ Object
- #authenticate(username, password) ⇒ Object
- #each(&block) ⇒ Object
- #find_by_username(name) ⇒ Object
-
#initialize ⇒ UserManager
constructor
A new instance of UserManager.
- #remove(name) ⇒ Object
- #save(path) ⇒ Object
Constructor Details
#initialize ⇒ UserManager
Returns a new instance of UserManager.
5 6 7 |
# File 'lib/yauth/user_manager.rb', line 5 def initialize @list = [] end |
Class Method Details
Instance Method Details
#add(user) ⇒ Object
9 10 11 12 |
# File 'lib/yauth/user_manager.rb', line 9 def add(user) remove(user.username) @list << user end |
#authenticate(username, password) ⇒ Object
32 33 34 35 |
# File 'lib/yauth/user_manager.rb', line 32 def authenticate(username, password) user = find_by_username(username) user if user and user.authenticate(password) end |
#each(&block) ⇒ Object
18 19 20 |
# File 'lib/yauth/user_manager.rb', line 18 def each(&block) @list.each(&block) end |
#find_by_username(name) ⇒ Object
28 29 30 |
# File 'lib/yauth/user_manager.rb', line 28 def find_by_username(name) @list.find { |u| u.username == name } end |
#remove(name) ⇒ Object
14 15 16 |
# File 'lib/yauth/user_manager.rb', line 14 def remove(name) @list.delete(find_by_username(name)) end |
#save(path) ⇒ Object
22 23 24 25 26 |
# File 'lib/yauth/user_manager.rb', line 22 def save(path) open(path, "w") do |io| io << @list.to_yaml end end |