ponder 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
1
4
  require 'test/unit'
2
5
 
3
- $LOAD_PATH.unshift Pathname.new(__FILE__).dirname.join('..', 'lib').expand_path
data/test/test_irc.rb CHANGED
@@ -1,130 +1,129 @@
1
- require 'pathname'
2
- $LOAD_PATH.unshift Pathname.new(__FILE__).dirname.expand_path
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+
3
3
  require 'test_helper'
4
- require 'ponder/irc'
5
- require 'ostruct'
4
+ require 'ponder/thaum'
6
5
 
7
- include Ponder::IRC
6
+ class TestIRC < Test::Unit::TestCase
7
+ def setup
8
+ @ponder = Ponder::Thaum.new
9
+
10
+ @ponder.configure do |c|
11
+ c.nick = 'Ponder'
12
+ c.username = 'Ponder'
13
+ c.real_name = 'Ponder Stibbons'
14
+ c.password = 'secret'
15
+ c.reconnect = true
16
+ end
8
17
 
9
- module Ponder
10
- module IRC
11
- def raw(message)
18
+ def @ponder.raw(message)
12
19
  $output << "#{message}\r\n"
13
20
  return "#{message}\r\n"
14
21
  end
15
- end
16
- end
17
22
 
18
- class TestIRC < Test::Unit::TestCase
19
- def setup
20
- @config = ::OpenStruct.new({:nick => 'Ponder',
21
- :username => 'Ponder',
22
- :real_name => 'Ponder Stibbons',
23
- :password => 'secret',
24
- :reconnect => true
25
- })
26
23
  $output = []
27
24
  end
28
-
25
+
29
26
  def test_message
30
- assert_equal("PRIVMSG recipient :foo bar baz\r\n", Ponder::IRC.message('recipient', 'foo bar baz')) # `message` is already defined, so we need to use Ponder::IRC
27
+ assert_equal("PRIVMSG recipient :foo bar baz\r\n", @ponder.message('recipient', 'foo bar baz'))
31
28
  end
32
-
29
+
33
30
  def test_register
34
- register
35
-
31
+ @ponder.register
32
+
36
33
  assert_equal(["NICK Ponder\r\n", "USER Ponder * * :Ponder Stibbons\r\n", "PASS secret\r\n"], $output)
37
34
  end
38
-
35
+
39
36
  def test_register_without_password
40
- @config.password = nil
41
- register
42
-
37
+ @ponder.configure { |c| c.password = nil }
38
+
39
+ @ponder.register
40
+
43
41
  assert_equal(["NICK Ponder\r\n", "USER Ponder * * :Ponder Stibbons\r\n"], $output)
44
42
  end
45
-
43
+
46
44
  def test_notice
47
- assert_equal("NOTICE Ponder :You are cool!\r\n", notice('Ponder', 'You are cool!'))
45
+ assert_equal("NOTICE Ponder :You are cool!\r\n", @ponder.notice('Ponder', 'You are cool!'))
48
46
  end
49
-
47
+
50
48
  def test_mode
51
- assert_equal("MODE Ponder +ao\r\n", mode('Ponder', '+ao'))
49
+ assert_equal("MODE Ponder +ao\r\n", @ponder.mode('Ponder', '+ao'))
52
50
  end
53
-
51
+
54
52
  def test_kick
55
- assert_equal("KICK #channel Nanny_Ogg\r\n", kick('#channel', 'Nanny_Ogg'))
53
+ assert_equal("KICK #channel Nanny_Ogg\r\n", @ponder.kick('#channel', 'Nanny_Ogg'))
56
54
  end
57
-
55
+
58
56
  def test_kick_with_reason
59
- assert_equal("KICK #channel Nanny_Ogg :Go away!\r\n", kick('#channel', 'Nanny_Ogg', 'Go away!'))
57
+ assert_equal("KICK #channel Nanny_Ogg :Go away!\r\n", @ponder.kick('#channel', 'Nanny_Ogg', 'Go away!'))
60
58
  end
61
-
59
+
62
60
  def test_action
63
- assert_equal("PRIVMSG #channel :\001ACTION HEX is working!\001\r\n", action('#channel', 'HEX is working!'))
61
+ assert_equal("PRIVMSG #channel :\001ACTION HEX is working!\001\r\n", @ponder.action('#channel', 'HEX is working!'))
64
62
  end
65
-
63
+
66
64
  def test_topic
67
- assert_equal("TOPIC #channel :I like dried frog pills.\r\n", topic('#channel', 'I like dried frog pills.'))
65
+ assert_equal("TOPIC #channel :I like dried frog pills.\r\n", @ponder.topic('#channel', 'I like dried frog pills.'))
68
66
  end
69
-
67
+
70
68
  def test_join
71
- assert_equal("JOIN #channel\r\n", join('#channel'))
69
+ assert_equal("JOIN #channel\r\n", @ponder.join('#channel'))
72
70
  end
73
-
71
+
74
72
  def test_join_with_password
75
- assert_equal("JOIN #channel secret\r\n", join('#channel', 'secret'))
73
+ assert_equal("JOIN #channel secret\r\n", @ponder.join('#channel', 'secret'))
76
74
  end
77
-
75
+
78
76
  def test_part
79
- assert_equal("PART #channel\r\n", part('#channel'))
77
+ assert_equal("PART #channel\r\n", @ponder.part('#channel'))
80
78
  end
81
-
79
+
82
80
  def test_part_with_message
83
- assert_equal("PART #channel :Partpart\r\n", part('#channel', 'Partpart'))
81
+ assert_equal("PART #channel :Partpart\r\n", @ponder.part('#channel', 'Partpart'))
84
82
  end
85
-
83
+
86
84
  def test_quit
87
- quit
88
-
85
+
86
+ @ponder.quit
87
+
89
88
  assert_equal(["QUIT\r\n"], $output)
90
89
  end
91
-
90
+
92
91
  def test_quit_with_message
93
- quit('GONE')
94
-
92
+ @ponder.quit('GONE')
93
+
95
94
  assert_equal(["QUIT :GONE\r\n"], $output)
96
95
  end
97
-
96
+
98
97
  def test_quit_reconnect_change
99
- assert_equal(true, @config.reconnect)
100
-
101
- quit
102
-
103
- assert_equal(false, @config.reconnect)
98
+ assert_equal(true, @ponder.config.reconnect)
99
+
100
+ @ponder.quit
101
+
102
+ assert_equal(false, @ponder.config.reconnect)
104
103
  end
105
-
104
+
106
105
  def test_rename
107
- assert_equal("NICK :Ridcully\r\n", rename('Ridcully'))
106
+ assert_equal("NICK :Ridcully\r\n", @ponder.rename('Ridcully'))
108
107
  end
109
-
108
+
110
109
  def test_away
111
- assert_equal("AWAY\r\n", away)
110
+ assert_equal("AWAY\r\n", @ponder.away)
112
111
  end
113
-
112
+
114
113
  def test_away_with_message
115
- assert_equal("AWAY :At the Mended Drum\r\n", away('At the Mended Drum'))
114
+ assert_equal("AWAY :At the Mended Drum\r\n", @ponder.away('At the Mended Drum'))
116
115
  end
117
-
116
+
118
117
  def test_back
119
- assert_equal("AWAY\r\n", back)
118
+ assert_equal("AWAY\r\n", @ponder.back)
120
119
  end
121
-
120
+
122
121
  def test_invite
123
- assert_equal("INVITE TheLibrarian #mended_drum\r\n", invite('TheLibrarian', '#mended_drum'))
122
+ assert_equal("INVITE TheLibrarian #mended_drum\r\n", @ponder.invite('TheLibrarian', '#mended_drum'))
124
123
  end
125
-
124
+
126
125
  def test_ban
127
- assert_equal("MODE #mended_drum +b foo!bar@baz\r\n", ban('#mended_drum', 'foo!bar@baz'))
126
+ assert_equal("MODE #mended_drum +b foo!bar@baz\r\n", @ponder.ban('#mended_drum', 'foo!bar@baz'))
128
127
  end
129
128
  end
130
129
 
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ponder
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 27
5
+ prerelease:
5
6
  segments:
6
7
  - 0
8
+ - 1
7
9
  - 0
8
- - 2
9
- version: 0.0.2
10
+ version: 0.1.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - "Tobias B\xC3\xBChlmann"
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-01-04 00:00:00 +01:00
18
+ date: 2011-01-29 00:00:00 +01:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -25,6 +26,7 @@ dependencies:
25
26
  requirements:
26
27
  - - ">="
27
28
  - !ruby/object:Gem::Version
29
+ hash: 59
28
30
  segments:
29
31
  - 0
30
32
  - 12
@@ -41,30 +43,28 @@ extensions: []
41
43
  extra_rdoc_files: []
42
44
 
43
45
  files:
46
+ - LICENSE
47
+ - README.md
48
+ - Rakefile
44
49
  - examples/echo.rb
45
50
  - examples/github_blog.rb
46
51
  - examples/redis_last_seen.rb
52
+ - lib/ponder.rb
47
53
  - lib/ponder/async_irc.rb
48
54
  - lib/ponder/callback.rb
49
55
  - lib/ponder/connection.rb
50
- - lib/ponder/delegate.rb
51
56
  - lib/ponder/filter.rb
52
57
  - lib/ponder/formatting.rb
53
58
  - lib/ponder/irc.rb
54
- - lib/ponder/thaum.rb
55
- - lib/ponder/version.rb
56
59
  - lib/ponder/logger/blind_io.rb
57
60
  - lib/ponder/logger/twoflogger.rb
58
- - lib/ponder/logger/twoflogger18.rb
59
- - lib/ruby/1.8/string.rb
60
- - lib/ponder.rb
61
+ - lib/ponder/thaum.rb
62
+ - lib/ponder/version.rb
63
+ - ponder.gemspec
61
64
  - test/test_async_irc.rb
62
65
  - test/test_callback.rb
63
66
  - test/test_helper.rb
64
67
  - test/test_irc.rb
65
- - LICENSE
66
- - ponder.gemspec
67
- - README.md
68
68
  has_rdoc: true
69
69
  homepage: http://github.com/tbuehlmann/ponder
70
70
  licenses: []
@@ -79,6 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
+ hash: 59
82
83
  segments:
83
84
  - 1
84
85
  - 8
@@ -89,13 +90,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
90
  requirements:
90
91
  - - ">="
91
92
  - !ruby/object:Gem::Version
93
+ hash: 3
92
94
  segments:
93
95
  - 0
94
96
  version: "0"
95
97
  requirements: []
96
98
 
97
99
  rubyforge_project:
98
- rubygems_version: 1.3.7
100
+ rubygems_version: 1.4.1
99
101
  signing_key:
100
102
  specification_version: 3
101
103
  summary: IRC bot framework
@@ -1,11 +0,0 @@
1
- module Ponder
2
- module Delegate
3
- def delegate
4
- thaum = self
5
-
6
- (IRC.instance_methods + [:configure, :on, :connect, :reload!, :reloading?]).each do |method|
7
- Object.send(:define_method, method) { |*args, &block| thaum.send(method, *args, &block) }
8
- end
9
- end
10
- end
11
- end
@@ -1,93 +0,0 @@
1
- require 'pathname'
2
- require 'thread'
3
- autoload :FileUtils, 'fileutils'
4
-
5
- module Ponder
6
- module Logger
7
- class Twoflogger
8
- attr_accessor :level, :levels, :time_format
9
-
10
- def initialize(destination = Ponder.root.join('logs', 'log.log'), level = :debug, time_format = '%Y-%m-%d %H:%M:%S', levels = {:debug => 0, :info => 1, :warn => 2, :error => 3, :fatal => 4, :unknown => 5})
11
- @level = level
12
- @time_format = time_format
13
- @levels = levels
14
- @queue = Queue.new
15
- @mutex = Mutex.new
16
- @running = false
17
-
18
- define_level_shorthand_methods
19
- self.log_dev = destination
20
- end
21
-
22
- def start_logging
23
- @running = true
24
- @thread = Thread.new do
25
- begin
26
- while @running do
27
- write(@queue.pop)
28
- end
29
- ensure
30
- @log_dev.close if @log_dev.is_a?(File)
31
- end
32
- end
33
- end
34
-
35
- def stop_logging
36
- @running = false
37
- end
38
-
39
- def log_dev=(destination)
40
- stop_logging
41
-
42
- if destination.is_a?(Pathname)
43
- unless destination.exist?
44
- unless destination.dirname.directory?
45
- FileUtils.mkdir_p destination.dirname
46
- end
47
-
48
- File.new(destination, 'w+')
49
- end
50
- @log_dev = File.open(destination, 'a+')
51
- @log_dev.sync = true
52
- elsif destination.is_a?(IO)
53
- @log_dev = destination
54
- else
55
- raise TypeError, 'need a Pathname or IO'
56
- end
57
- end
58
-
59
- private
60
-
61
- def define_level_shorthand_methods
62
- @levels.each_pair do |level_name, severity|
63
- self.class.send(:define_method, level_name, Proc.new { |*messages| queue(severity, *messages) })
64
- end
65
- end
66
-
67
- def queue(severity, *messages)
68
- raise(ArgumentError, 'Need a message') if messages.empty?
69
- raise(ArgumentError, 'Need messages that respond to #to_s') if messages.any? { |message| !message.respond_to?(:to_s) }
70
-
71
- if severity >= @levels[@level]
72
- message_hashes = messages.map { |message| {:severity => severity, :message => message} }
73
-
74
- @mutex.synchronize do
75
- message_hashes.each do |hash|
76
- @queue << hash
77
- end
78
- end
79
- end
80
- end
81
-
82
- def write(*message_hashes)
83
- begin
84
- message_hashes.each do |hash|
85
- @log_dev.puts "#{@levels.index(hash[:severity])} #{Time.now.strftime(@time_format)} #{hash[:message]}"
86
- end
87
- rescue => e
88
- puts e.message, *e.backtrace
89
- end
90
- end
91
- end
92
- end
93
- end
@@ -1,5 +0,0 @@
1
- class String
2
- def force_encoding(arg)
3
- self
4
- end
5
- end