Class: Cinch::UserList
- Inherits:
-
CachedList
- Object
- CachedList
- Cinch::UserList
- Defined in:
- lib/cinch/user_list.rb
Overview
Note:
In prior versions, this class was called UserManager
Instance Method Summary collapse
-
#delete(user)
private
-
#find(nick) ⇒ User?
Finds a user.
-
#find_ensured(*args) ⇒ User
Finds or creates a user.
-
#update_nick(user)
private
Methods inherited from CachedList
Constructor Details
This class inherits a constructor from Cinch::CachedList
Instance Method Details
#delete(user)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
83 84 85 |
# File 'lib/cinch/user_list.rb', line 83 def delete(user) @cache.delete_if {|n, u| u == user } end |
#find(nick) ⇒ User?
Finds a user.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/cinch/user_list.rb', line 61 def find(nick) if nick == @bot.nick return @bot end downcased_nick = nick.irc_downcase(@bot.irc.isupport["CASEMAPPING"]) @mutex.synchronize do return @cache[downcased_nick] end end |
#find_ensured(nick) ⇒ User #find_ensured(user, nick, host) ⇒ User
Finds or creates a user.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cinch/user_list.rb', line 24 def find_ensured(*args) user, host = nil, nil case args.size when 1 nick = args.first = [nick] when 3 nick = args[1] = args user, _, host = else raise ArgumentError end if nick == @bot.nick user_obj = @bot end downcased_nick = nick.irc_downcase(@bot.irc.isupport["CASEMAPPING"]) @mutex.synchronize do if user_obj.nil? user_obj = @cache[downcased_nick] ||= User.new(*, @bot) end if user && host # Explicitly set user and host whenever we request a User # object to update them on e.g. JOIN. user_obj.sync(:user, user, true) user_obj.sync(:host, host, true) end user_obj end end |
#update_nick(user)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
74 75 76 77 78 79 |
# File 'lib/cinch/user_list.rb', line 74 def update_nick(user) @mutex.synchronize do @cache.delete user.last_nick.irc_downcase(@bot.irc.isupport["CASEMAPPING"]) @cache[user.nick.irc_downcase(@bot.irc.isupport["CASEMAPPING"])] = user end end |