Skip to content

Commit f910c50

Browse files
committedMay 2, 2012
rename #puts so you can puts while you puts
1 parent 20dbca5 commit f910c50

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed
 

‎services/irc.rb

+16-15
Original file line numberDiff line numberDiff line change
@@ -37,34 +37,35 @@ def send_messages(messages)
3737
botname = data['nick'].to_s.empty? ? "GitHub#{rand(200)}" : data['nick']
3838
command = data['notice'].to_i == 1 ? 'NOTICE' : 'PRIVMSG'
3939

40-
self.puts "PASS #{data['password']}" if !data['password'].to_s.empty?
41-
self.puts "NICK #{botname}"
42-
self.puts "MSG NICKSERV IDENTIFY #{data['nickservidentify']}" if !data['nickservidentify'].to_s.empty?
43-
self.puts "USER #{botname} 8 * :GitHub IRCBot"
40+
irc_puts "PASS #{data['password']}" if !data['password'].to_s.empty?
41+
irc_puts "NICK #{botname}"
42+
irc_puts "MSG NICKSERV IDENTIFY #{data['nickservidentify']}" if !data['nickservidentify'].to_s.empty?
43+
irc_puts "USER #{botname} 8 * :GitHub IRCBot"
4444

4545
loop do
46-
case self.gets
46+
case irc_gets
4747
when / 00[1-4] #{Regexp.escape(botname)} /
4848
break
4949
when /^PING\s*:\s*(.*)$/
50-
self.puts "PONG #{$1}"
50+
irc_puts "PONG #{$1}"
5151
end
5252
end
5353

5454
without_join = data['message_without_join'] == '1'
5555
rooms.each do |room|
5656
room, pass = room.split("::")
57-
self.puts "JOIN #{room} #{pass}" unless without_join
57+
irc_puts "JOIN #{room} #{pass}" unless without_join
5858

5959
Array(messages).each do |message|
60-
self.puts "#{command} #{room} :#{message}"
60+
irc_puts "#{command} #{room} :#{message}"
6161
end
6262

63-
self.puts "PART #{room}" unless without_join
63+
irc_puts "PART #{room}" unless without_join
6464
end
6565

66-
self.puts "QUIT"
67-
self.gets until self.eof?
66+
irc_puts "QUIT"
67+
irc_response = []
68+
irc_response << irc_gets unless irc_eof?
6869
rescue SocketError => boom
6970
if boom.to_s =~ /getaddrinfo: Name or service not known/
7071
raise_config_error 'Invalid host'
@@ -79,15 +80,15 @@ def send_messages(messages)
7980
raise_config_error 'Host does not support SSL'
8081
end
8182

82-
def gets
83+
def irc_gets
8384
irc.gets
8485
end
8586

86-
def eof?
87+
def irc_eof?
8788
irc.eof?
8889
end
8990

90-
def puts(*args)
91+
def irc_puts(*args)
9192
irc.puts *args
9293
end
9394

@@ -125,7 +126,7 @@ def format_commit_message(commit)
125126
"\002#{sha1[0..6]}\002 (#{files.size} files in #{dirs.size} dirs): #{short}"
126127
end
127128
end
128-
129+
129130
def branch_name_matches?
130131
return true if data['branch_regexes'].nil?
131132
return true if data['branch_regexes'].strip == ""

‎test/irc_test.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ def writable_io
1111
@writable_io ||= StringIO.new
1212
end
1313

14-
def puts(*args)
14+
def irc_puts(*args)
1515
writable_io.puts *args
1616
end
1717

18-
def gets
18+
def irc_gets
1919
readable_io.gets
2020
end
2121

22-
def eof?
22+
def irc_eof?
2323
true
2424
end
2525

@@ -44,10 +44,10 @@ def test_push
4444
assert_equal "QUIT", msgs.shift.strip
4545
assert_nil msgs.shift
4646
end
47-
47+
4848
def test_push_with_empty_branch_regex
4949
svc = service({'room' => 'r', 'nick' => 'n', 'branch_regexes' => ''}, payload)
50-
50+
5151
svc.receive_push
5252
msgs = svc.writable_io.string.split("\n")
5353
assert_equal "NICK n", msgs.shift
@@ -61,7 +61,7 @@ def test_push_with_empty_branch_regex
6161
assert_equal "QUIT", msgs.shift.strip
6262
assert_nil msgs.shift
6363
end
64-
64+
6565
def test_push_with_single_matching_branch_regex
6666
svc = service({'room' => 'r', 'nick' => 'n', 'branch_regexes' => 'mast*'}, payload)
6767

@@ -78,15 +78,15 @@ def test_push_with_single_matching_branch_regex
7878
assert_equal "QUIT", msgs.shift.strip
7979
assert_nil msgs.shift
8080
end
81-
81+
8282
def test_push_with_single_mismatching_branch_regex
8383
svc = service({'room' => 'r', 'nick' => 'n', 'branch_regexes' => '^ticket*'}, payload)
8484

8585
svc.receive_push
8686
msgs = svc.writable_io.string.split("\n")
8787
assert_nil msgs.shift
8888
end
89-
89+
9090
def test_push_with_multiple_branch_regexes_where_all_match
9191
svc = service({'room' => 'r', 'nick' => 'n', 'branch_regexes' => 'mast*,^ticket*'}, payload)
9292

0 commit comments

Comments
 (0)
Please sign in to comment.