rhuidean 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/rhuidean.rb CHANGED
@@ -9,7 +9,7 @@ module Rhuidean
9
9
  # Version number
10
10
  V_MAJOR = 1
11
11
  V_MINOR = 1
12
- V_PATCH = 0
12
+ V_PATCH = 2
13
13
 
14
14
  VERSION = "#{V_MAJOR}.#{V_MINOR}.#{V_PATCH}"
15
15
  end
@@ -192,14 +192,15 @@ class Client
192
192
  #
193
193
  def read
194
194
  begin
195
- ret = @socket.readpartial(8192)
196
- rescue Errno::EAGAIN
195
+ ret = @socket.read_nonblock(8192)
196
+ rescue IO::WaitReadable
197
197
  retry
198
- rescue EOFError, SystemCallError
198
+ rescue Exception
199
199
  ret = nil # Dead
200
200
  end
201
201
 
202
202
  if not ret or ret.empty?
203
+ log(:info, "read error from #@server: #{e}") if e
203
204
  @eventq.post(:dead)
204
205
  return
205
206
  end
@@ -232,11 +233,11 @@ class Client
232
233
  begin
233
234
  # Use shift because we need it to fall off immediately.
234
235
  while line = @sendq.shift
236
+ log(:debug, "<- #{line}")
235
237
  line += "\r\n"
236
- log(:debug, line)
237
- @socket.write(line)
238
+ @socket.write_nonblock(line)
238
239
  end
239
- rescue Errno::EAGAIN
240
+ rescue IO::WaitReadable
240
241
  retry
241
242
  rescue Exception
242
243
  @eventq.post(:dead)
@@ -281,7 +282,7 @@ class Client
281
282
  @recvq.each do |line|
282
283
  line.chomp!
283
284
 
284
- log(:debug, line)
285
+ log(:debug,"-> #{line}")
285
286
 
286
287
  m = IRC_RE.match(line)
287
288
 
@@ -7,6 +7,42 @@
7
7
  # encoding: utf-8
8
8
 
9
9
  module Loggable
10
+
11
+ #
12
+ # I use this to override the log formatting.
13
+ # There's no documented way to do this; I had to figure it out.
14
+ # That means this could break, and it's not "right."
15
+ #
16
+ class Formatter
17
+ FORMAT = "%s, [%s] %s: %s\n"
18
+ PN_RE = /\:in \`.+\'/
19
+
20
+ ######
21
+ public
22
+ ######
23
+
24
+ #
25
+ # Called by Logger to format the message.
26
+ # ---
27
+ # severity:: String
28
+ # time:: Time
29
+ # progname:: String
30
+ # msg:: strictly anything, for us String
31
+ #
32
+ def call(severity, time, progname, msg)
33
+ datetime = time.strftime('%m/%d %H:%M:%S')
34
+
35
+ # Include filename, line number, and method name in debug
36
+ if severity == "DEBUG"
37
+ progname.gsub!(PN_RE, '')
38
+ progname.gsub!('block in ', '')
39
+ "[%s] %s: %s\n" % [datetime, progname, msg]
40
+ else
41
+ "[%s] %s\n" % [datetime, msg]
42
+ end
43
+ end
44
+ end
45
+
10
46
  ##
11
47
  # Logs a regular message.
12
48
  # ---
@@ -34,7 +70,7 @@ module Loggable
34
70
  # Set to false/nil to disable logging...
35
71
  return unless @logger
36
72
 
37
- @logger.datetime_format = '%m/%d %H:%M:%S '
73
+ @logger.formatter = Formatter.new
38
74
  end
39
75
 
40
76
  def log_level=(level)
@@ -179,7 +179,7 @@ class StatefulClient < Client
179
179
  @users[user.nickname] ||= user
180
180
 
181
181
  @channels[m.target].add_user(user)
182
- log(:info, "join: #{user} -> #{m.target}")
182
+ log(:info, "do_join(): #{user} -> #{m.target}")
183
183
  end
184
184
  end
185
185
 
@@ -196,12 +196,12 @@ class StatefulClient < Client
196
196
 
197
197
  @channels.delete(chan.name)
198
198
 
199
- log(:info, "parted: #{chan.name}")
199
+ log(:info, "do_part(): #{chan.name}")
200
200
  else
201
201
  user = @users[m.origin_nick]
202
202
 
203
203
  @channels[m.target].delete_user(user)
204
- log(:info, "part: #{user.nickname} -> #{m.origin_nick}")
204
+ log(:info, "do_part(): #{user.nickname} -> #{m.origin_nick}")
205
205
 
206
206
  delete_user(user) if user.channels.empty?
207
207
  end
@@ -222,7 +222,7 @@ class StatefulClient < Client
222
222
  channel.users.delete(m.origin_nick)
223
223
  end
224
224
 
225
- log(:info, "nick: #{m.origin_nick} -> #{m.target}")
225
+ log(:info, "do_nick(): #{m.origin_nick} -> #{m.target}")
226
226
  end
227
227
 
228
228
  def do_kick(m)
@@ -238,12 +238,12 @@ class StatefulClient < Client
238
238
 
239
239
  @channels.delete(chan.name)
240
240
 
241
- log(:info, "kicked: #{chan.name}")
241
+ log(:info, "do_kick(): #{chan.name}")
242
242
  else
243
243
  user = @users[m.params[0]]
244
244
 
245
245
  @channels[m.target].delete_user(user)
246
- log(:info, "kick: #{user.nickname} -> #{m.origin_nick}")
246
+ log(:info, "do_kick(): #{user.nickname} -> #{m.origin_nick}")
247
247
 
248
248
  delete_user(user) if user.channels.empty?
249
249
  end
@@ -258,7 +258,7 @@ class StatefulClient < Client
258
258
  user.channels.each { |name, chan| chan.delete_user(user) }
259
259
 
260
260
  delete_user(user)
261
- log(:info, "quit: #{user.nickname}")
261
+ log(:info, "do_quit(): #{user.nickname}")
262
262
  end
263
263
  end
264
264
 
@@ -294,7 +294,7 @@ class StatefulClient < Client
294
294
  end
295
295
 
296
296
  chan.add_user(user)
297
- log(:debug, "names: #{user} -> #{chan}")
297
+ log(:debug, "do_rpl_namereply(): #{user} -> #{chan}")
298
298
  end
299
299
  end
300
300
  end
data/test/tc_client.rb CHANGED
@@ -42,7 +42,6 @@ class TestClient < Test::Unit::TestCase
42
42
  c.realname = 'rhuidean unit tester'
43
43
 
44
44
  c.logger = nil
45
- c.debug = false
46
45
  end
47
46
  end
48
47
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 1
8
- - 0
9
- version: 1.1.0
8
+ - 2
9
+ version: 1.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Eric Will
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-11 00:00:00 -05:00
17
+ date: 2010-11-28 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -32,10 +32,10 @@ files:
32
32
  - lib/rhuidean.rb
33
33
  - lib/rhuidean/client.rb
34
34
  - lib/rhuidean/timer.rb
35
- - lib/rhuidean/event.rb
35
+ - lib/rhuidean/stateful_channel.rb
36
36
  - lib/rhuidean/methods.rb
37
+ - lib/rhuidean/event.rb
37
38
  - lib/rhuidean/numeric.rb
38
- - lib/rhuidean/stateful_channel.rb
39
39
  - lib/rhuidean/stateful_client.rb
40
40
  - lib/rhuidean/stateful_user.rb
41
41
  - lib/rhuidean/loggable.rb