Class: IRC::Server::Dispatcher::ConnectionDispatcher::Connections

Inherits:
Object
  • Object
show all
Defined in:
lib/failirc/server/dispatcher/connectiondispatcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ Connections

Returns a new instance of Connections.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/failirc/server/dispatcher/connectiondispatcher.rb', line 37

def initialize (server)
    @server = server
    
    @data = ThreadSafeHash.new
    
    @data[:listening] = {
        :sockets => [],
        :data    => {},
    }
    
    @data[:sockets] = []
    @data[:things]  = {}
    @data[:clients] = CaseInsensitiveHash.new
    @data[:links]   = CaseInsensitiveHash.new
end

Instance Attribute Details

#serverObject (readonly)

Returns the value of attribute server.



35
36
37
# File 'lib/failirc/server/dispatcher/connectiondispatcher.rb', line 35

def server
  @server
end

Instance Method Details

#clientsObject



65
66
67
# File 'lib/failirc/server/dispatcher/connectiondispatcher.rb', line 65

def clients
    @data[:clients]
end

#delete(socket) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/failirc/server/dispatcher/connectiondispatcher.rb', line 81

def delete (socket)
    if !exists?(socket)
        return
    end

    thing = @data[:things][socket]
    
    if thing.is_a?(Client)
        @data[:clients].delete(thing.nick)
        @data[:clients].delete(socket)
    elsif thing.is_a?(Link)
        @data[:links].delete(thing.host)
        @data[:links].delete(socket)
    end
    
    @data[:sockets].delete(socket)
    @data[:things].delete(socket)
end

#empty?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/failirc/server/dispatcher/connectiondispatcher.rb', line 73

def empty?
    sockets.empty?
end

#exists?(socket) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/failirc/server/dispatcher/connectiondispatcher.rb', line 77

def exists? (socket)
    things[socket] ? true : false
end


69
70
71
# File 'lib/failirc/server/dispatcher/connectiondispatcher.rb', line 69

def links
    @data[:links]
end

#listeningObject



53
54
55
# File 'lib/failirc/server/dispatcher/connectiondispatcher.rb', line 53

def listening
    @data[:listening]
end

#socketsObject



57
58
59
# File 'lib/failirc/server/dispatcher/connectiondispatcher.rb', line 57

def sockets
    @data[:sockets]
end

#thingsObject



61
62
63
# File 'lib/failirc/server/dispatcher/connectiondispatcher.rb', line 61

def things
    @data[:things]
end