Class: IRC::Server::Users

Inherits:
ThreadSafeHash show all
Defined in:
lib/failirc/server/users.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel, *args) ⇒ Users

Returns a new instance of Users.



31
32
33
34
35
36
# File 'lib/failirc/server/users.rb', line 31

def initialize (channel, *args)
    @server  = channel.server
    @channel = channel

    super(*args)
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



29
30
31
# File 'lib/failirc/server/users.rb', line 29

def channel
  @channel
end

#serverObject (readonly)

Returns the value of attribute server.



29
30
31
# File 'lib/failirc/server/users.rb', line 29

def server
  @server
end

Instance Method Details

#[](user) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/failirc/server/users.rb', line 44

def [] (user)
    if user.is_a?(Client) || user.is_a?(User)
        user = user.nick
    end

    __get(user)
end

#[]=(user, value) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/failirc/server/users.rb', line 54

def []= (user, value)
    if user.is_a?(Client) || user.is_a?(User)
        user = user.nick
    end

    __set(user, value)
end

#__deleteObject



62
# File 'lib/failirc/server/users.rb', line 62

alias __delete delete

#__getObject



42
# File 'lib/failirc/server/users.rb', line 42

alias __get []

#__setObject



52
# File 'lib/failirc/server/users.rb', line 52

alias __set []=

#add(user) ⇒ Object



84
85
86
87
88
89
90
91
92
# File 'lib/failirc/server/users.rb', line 84

def add (user)
    if user.is_a?(Client)
        self[user.nick] = User.new(user, @channel)
    elsif user.is_a?(User)
        self[user.nick] = user
    else
        raise 'You can only add Client or User.'
    end
end

#delete(key) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/failirc/server/users.rb', line 64

def delete (key)
    if key.is_a?(User) || key.is_a?(Client)
        key = key.nick
    end

    key = key.downcase

    user = self[key]

    if user
        __delete(key)

        if channel.empty?
            server.channels.delete(channel)
        end
    end

    return user
end

#send(*args) ⇒ Object



94
95
96
97
98
# File 'lib/failirc/server/users.rb', line 94

def send (*args)
    each_value {|user|
        user.send(*args)
    }
end