Class: IRC::Server::Dispatcher::ConnectionDispatcher::Data
- Defined in:
- lib/failirc/server/dispatcher/connectiondispatcher.rb
Instance Attribute Summary collapse
-
#dispatcher ⇒ Object
readonly
Returns the value of attribute dispatcher.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
- #[](socket) ⇒ Object
- #clear(socket) ⇒ Object
- #delete(socket) ⇒ Object
- #each(&block) ⇒ Object
- #empty?(socket = nil) ⇒ Boolean
- #first(socket) ⇒ Object
-
#initialize(dispatcher) ⇒ Data
constructor
A new instance of Data.
- #last(socket) ⇒ Object
- #pop(socket) ⇒ Object
- #push(socket, string) ⇒ Object
Constructor Details
#initialize(dispatcher) ⇒ Data
Returns a new instance of Data.
104 105 106 107 108 109 |
# File 'lib/failirc/server/dispatcher/connectiondispatcher.rb', line 104 def initialize (dispatcher) @server = dispatcher.server @dispatcher = dispatcher @data = ThreadSafeHash.new end |
Instance Attribute Details
#dispatcher ⇒ Object (readonly)
Returns the value of attribute dispatcher.
102 103 104 |
# File 'lib/failirc/server/dispatcher/connectiondispatcher.rb', line 102 def dispatcher @dispatcher end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
102 103 104 |
# File 'lib/failirc/server/dispatcher/connectiondispatcher.rb', line 102 def server @server end |
Instance Method Details
#[](socket) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/failirc/server/dispatcher/connectiondispatcher.rb', line 111 def [] (socket) if socket.is_a?(Client) || socket.is_a?(User) socket = socket.socket end if !@data[socket].is_a?(Array) @data[socket] = [] end @data[socket] end |
#clear(socket) ⇒ Object
145 146 147 |
# File 'lib/failirc/server/dispatcher/connectiondispatcher.rb', line 145 def clear (socket) self[socket].clear end |
#delete(socket) ⇒ Object
149 150 151 152 153 154 155 |
# File 'lib/failirc/server/dispatcher/connectiondispatcher.rb', line 149 def delete (socket) if socket.is_a?(Client) || socket.is_a?(User) socket = socket.socket end @data.delete(socket) end |
#each(&block) ⇒ Object
181 182 183 |
# File 'lib/failirc/server/dispatcher/connectiondispatcher.rb', line 181 def each (&block) @data.each_key &block end |
#empty?(socket = nil) ⇒ Boolean
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/failirc/server/dispatcher/connectiondispatcher.rb', line 165 def empty? (socket=nil) if socket.is_a?(Client) || socket.is_a?(User) socket = socket.socket end if socket if @data.has_key?(socket) return @data[socket].empty? else return true end else return @data.empty? end end |
#first(socket) ⇒ Object
157 158 159 |
# File 'lib/failirc/server/dispatcher/connectiondispatcher.rb', line 157 def first (socket) self[socket].first end |
#last(socket) ⇒ Object
161 162 163 |
# File 'lib/failirc/server/dispatcher/connectiondispatcher.rb', line 161 def last (socket) self[socket].last end |
#pop(socket) ⇒ Object
141 142 143 |
# File 'lib/failirc/server/dispatcher/connectiondispatcher.rb', line 141 def pop (socket) self[socket].shift end |
#push(socket, string) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/failirc/server/dispatcher/connectiondispatcher.rb', line 123 def push (socket, string) if string.is_a?(String) string.lstrip! end if string == :EOC if socket.is_a?(Client) || socket.is_a?(User) socket = socket.socket end dispatcher.disconnecting.push({ :thing => dispatcher.connections.things[socket], :output => self[socket] }) end if (string && !string.empty?) || self[socket].last == :EOC self[socket].push(string) end end |