sponge 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -8,15 +8,14 @@ require "lib/sponge/version"
8
8
  NAME = 'sponge'
9
9
  VERSION = Sponge::VERSION
10
10
  TITLE = "Sponge: The simple IRC library"
11
- CLEAN.include ["*.gem", ".config", "rdoc"]
11
+ CLEAN.include ["*.gem", "doc"]
12
12
  RDOC_OPTS = [
13
- "--line-numbers", "--inline-source",
14
- "--title", TITLE,
13
+ "-U", "--title", TITLE,
15
14
  "--main", "README.rdoc"
16
15
  ]
17
16
 
18
17
  Rake::RDocTask.new do |rdoc|
19
- rdoc.rdoc_dir = "rdoc"
18
+ rdoc.rdoc_dir = "doc"
20
19
  rdoc.options += RDOC_OPTS
21
20
  rdoc.rdoc_files.add %w(README.rdoc lib/**/*.rb)
22
21
  end
@@ -48,7 +47,7 @@ end
48
47
 
49
48
  desc "Upload rdoc to injekt.net"
50
49
  task :upload do
51
- sh("scp -rP 2295 rdoc/ injekt@injekt.net:/var/www/localhost/rdoc.injekt.net/sponge")
50
+ sh("scp -rP 2295 doc/* injekt@injekt.net:/var/www/localhost/rdoc.injekt.net/sponge")
52
51
  end
53
52
 
54
- task :default => [:rdoc, :package]
53
+ task :default => [:clean, :rdoc, :package]
@@ -41,9 +41,16 @@ module Sponge
41
41
  # Client configuration options
42
42
  attr_reader :config
43
43
 
44
+ # Our Listeners Object
45
+ attr_reader :listeners
46
+
44
47
  def initialize(server=nil, opts={}, &blk)
45
- @config = OpenStruct.new(opts.merge(OptionsDSL.new(server, &blk).options))
46
- @config.port ||= 6667
48
+ config = opts.merge(OptionsDSL.new(server, &blk).options)
49
+ config = OpenStruct.new(opts.merge(config))
50
+ @config = config
51
+
52
+ config.port ||= 6667
53
+ raise(ArgumentError, "No server supplied") unless config.server
47
54
 
48
55
  @irc = IRC::Socket.new(config.server, config.port)
49
56
  @irc.client = self
@@ -108,7 +115,8 @@ module Sponge
108
115
  private
109
116
 
110
117
  def setup_username
111
- raise "You must set a nickname" unless nick = config.nickname
118
+ nick = config.nickname || 'Sponge'
119
+ config.nickname ||= nick
112
120
  config.username ||= nick
113
121
  config.hostname ||= nick
114
122
  config.realname ||= nick
@@ -125,7 +133,7 @@ module Sponge
125
133
  def initialize(server=nil, &blk)
126
134
  @options = {}
127
135
  server(server) if server
128
- instance_eval(&blk)
136
+ instance_eval(&blk) if block_given?
129
137
  end
130
138
 
131
139
  def server(val)
@@ -41,6 +41,7 @@ module Sponge
41
41
  raise "listener for #{command} already exists" if @list.key?(command)
42
42
  @list[command] = Listener.new(command, &blk)
43
43
  end
44
+ commands
44
45
  end
45
46
 
46
47
  # Remove a listener from our list
@@ -52,6 +53,10 @@ module Sponge
52
53
  @list[command]
53
54
  end
54
55
 
56
+ def include?(k)
57
+ @list.key?(k)
58
+ end
59
+
55
60
  # Invoke #call on a Listener if it exists passing an IRC::Message
56
61
  def handle(message)
57
62
  raise "Not a IRC::Message" unless message.is_a?(Sponge::IRC::Message)
@@ -1,7 +1,7 @@
1
1
  module Sponge
2
2
  MAJOR = 0
3
3
  MINOR = 2
4
- TINY = 8
4
+ TINY = 9
5
5
 
6
6
  VERSION = [MAJOR, MINOR, TINY].join('.')
7
7
 
@@ -0,0 +1,10 @@
1
+ require File.expand_path('../../lib/sponge.rb', __FILE__)
2
+ require 'bacon'
3
+
4
+ class Sponge::IRC::Socket
5
+ def write(data)
6
+ nil
7
+ end
8
+ end
9
+
10
+ # Add some mock IRC server stuff for real testing
@@ -0,0 +1,45 @@
1
+ require File.expand_path('../../../helper', __FILE__)
2
+
3
+ client = Sponge::IRC::Client.new('irc.freenode.org')
4
+
5
+ describe "Sponge::IRC::Client" do
6
+
7
+ it "should default to port 6667" do
8
+ client.config.port.should == 6667
9
+ end
10
+
11
+ it "should default to nickname 'Sponge'" do
12
+ client.config.nickname.should == 'Sponge'
13
+ end
14
+
15
+ it "should use the default nickname if no username, hostname, or realname are supplied" do
16
+ c = Sponge::IRC::Client.new('', :nickname => 'foobot')
17
+
18
+ [:username, :hostname, :realname].each do |attr|
19
+ c.config.send(attr).should == 'foobot'
20
+ end
21
+ end
22
+
23
+ describe "#set_nick" do
24
+ it "should change the nickname" do
25
+ client.set_nick("Spongebot")
26
+
27
+ client.config.nickname.should.not == 'Sponge'
28
+ client.config.nickname.should == 'Spongebot'
29
+ end
30
+ end
31
+
32
+ describe "#on" do
33
+ it "should create a listener" do
34
+ client.on('foo')
35
+ client.listeners.include?('foo').should.be.true
36
+ client.listeners.all.should.include?('foo')
37
+ end
38
+
39
+ it "should return a list of commands we've added listeners to" do
40
+ listeners = client.on(:bar, :baz)
41
+ listeners.should.equal [:bar, :baz]
42
+ end
43
+ end
44
+
45
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 8
9
- version: 0.2.8
8
+ - 9
9
+ version: 0.2.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - Lee 'injekt' Jarvis
@@ -16,8 +16,21 @@ cert_chain: []
16
16
 
17
17
  date: 2010-04-05 00:00:00 +01:00
18
18
  default_executable:
19
- dependencies: []
20
-
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: bacon
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 1
30
+ - 0
31
+ version: 1.1.0
32
+ type: :development
33
+ version_requirements: *id001
21
34
  description: A simple IRC library
22
35
  email: ljjarvis@gmail.com
23
36
  executables: []
@@ -31,6 +44,8 @@ files:
31
44
  - Rakefile
32
45
  - examples/client.rb
33
46
  - examples/socket.rb
47
+ - spec/sponge/irc/client.rb
48
+ - spec/helper.rb
34
49
  - lib/sponge/version.rb
35
50
  - lib/sponge/irc/listeners.rb
36
51
  - lib/sponge/irc/client.rb
@@ -46,8 +61,6 @@ licenses: []
46
61
  post_install_message:
47
62
  rdoc_options:
48
63
  - --quiet
49
- - --line-numbers
50
- - --inline-source
51
64
  - --title
52
65
  - "Sponge: The Simple IRC library"
53
66
  - --main