vetinari 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78880d961649c425e2c89754d7236fada5a8768e
4
- data.tar.gz: 4aeabaeb70c5e9be616ff847c8d624b8462590c5
3
+ metadata.gz: fe414b4c35924d0c5fa15e67e84494b74b23f31f
4
+ data.tar.gz: 5e82b546876eb70fe159d0c9480fdeffbecbfacf
5
5
  SHA512:
6
- metadata.gz: b7fcf851e371ebae8069adaf5eb7c7f820b9bfd2dd77b244454229cf46466d5ebf4d23ad8fccaedaeffc09a7e4ee4003ea47b0f9ad986a61b72d24b16d8c5e2c
7
- data.tar.gz: b0c4bb57dcb1f311d22ade88c91e5372b0ebf555529cf4d9f94c073b1ac088f1ef4fef08de5f34a044f9152340b385810448acb960ce6c0a773c0ea7c080f3cf
6
+ metadata.gz: d0c60adeae677929cb9d903674432787c854c9185fd924e89443a65ffc5b1c1f1668e4c26e3fd2ea307405c453324f4a7faa509b6e12de97890ce80065742227
7
+ data.tar.gz: 9760ed1524abde7e444ada03ec74c4728467ceffb65ec21879ff0b7bcdab9c989af0fc1e9a88e77751e648ea9c12eeca763e5ded23e794d5f60df0e3baad82a0
@@ -4,6 +4,8 @@ module Vetinari
4
4
 
5
5
  attr_reader :config, :users, :user, :channels, :server_manager, :callbacks
6
6
 
7
+ finalizer :finalize
8
+
7
9
  def initialize(&block)
8
10
  @actor = Actor.current
9
11
  @config = Configuration.new(&block)
@@ -75,6 +77,21 @@ module Vetinari
75
77
  end
76
78
  end
77
79
 
80
+ def finalize
81
+ if connected?
82
+ quit
83
+ @socket.close rescue nil
84
+ end
85
+
86
+ @callbacks.terminate_callbacks
87
+ @users.terminate
88
+ @channels.terminate
89
+
90
+ links.each do |actor|
91
+ actor.terminate if actor.alive?
92
+ end
93
+ end
94
+
78
95
  private
79
96
 
80
97
  def disconnected
@@ -85,5 +85,13 @@ module Vetinari
85
85
  def inspect
86
86
  "#<CallbackContainer bot=#{@bot.inspect}>"
87
87
  end
88
+
89
+ def terminate_callbacks
90
+ @callbacks.each do |event, hash|
91
+ hash.each do |uuid, _hash|
92
+ _hash[:callback].terminate
93
+ end
94
+ end
95
+ end
88
96
  end
89
97
  end
@@ -17,6 +17,8 @@ module Vetinari
17
17
  @modes = {}
18
18
  @lists = Hash.new { |hash, key| hash[key] = [] }
19
19
  @mutex = Mutex.new
20
+
21
+ link(@bot)
20
22
  end
21
23
 
22
24
  # Experimental, no tests so far.
@@ -105,7 +107,7 @@ module Vetinari
105
107
  callbacks << @bot.on(:join) do |env|
106
108
  if env[:channel].name == @name
107
109
  condition.signal :joined
108
- callbacks.each { |cb| cb.remove_and_terminate }
110
+ callbacks.each { |cb| cb.remove_and_terminate if cb.alive? }
109
111
  end
110
112
  end
111
113
 
@@ -122,14 +124,14 @@ module Vetinari
122
124
 
123
125
  if channel_name == @name
124
126
  condition.signal msg
125
- callbacks.each { |cb| cb.remove_and_terminate }
127
+ callbacks.each { |cb| cb.remove_and_terminate if cb.alive? }
126
128
  end
127
129
  end
128
130
  end
129
131
 
130
132
  after(5) do
131
133
  condition.signal :timeout
132
- callbacks.each { |cb| cb.remove_and_terminate }
134
+ callbacks.each { |cb| cb.remove_and_terminate if cb.alive? }
133
135
  end
134
136
 
135
137
  if key
@@ -4,6 +4,8 @@ module Vetinari
4
4
 
5
5
  attr_reader :channels
6
6
 
7
+ finalizer :finalize
8
+
7
9
  exclusive
8
10
 
9
11
  def initialize
@@ -70,5 +72,9 @@ module Vetinari
70
72
 
71
73
  users
72
74
  end
75
+
76
+ def finalize
77
+ @channels.each(&:terminate)
78
+ end
73
79
  end
74
80
  end
@@ -19,7 +19,7 @@ module Vetinari
19
19
  callbacks << on(:nick_change) do |env|
20
20
  if env[:user].bot?
21
21
  condition.signal env[:user].nick
22
- callbacks.each { |cb| cb.remove_and_terminate }
22
+ callbacks.each { |cb| cb.remove_and_terminate if cb.alive? }
23
23
  end
24
24
  end
25
25
 
@@ -31,13 +31,13 @@ module Vetinari
31
31
  raw_messages.each do |raw, msg|
32
32
  callbacks << on(raw) do |env|
33
33
  condition.signal(msg)
34
- callbacks.each { |cb| cb.remove_and_terminate }
34
+ callbacks.each { |cb| cb.remove_and_terminate if cb.alive? }
35
35
  end
36
36
  end
37
37
 
38
38
  after(5) do
39
39
  condition.signal(:timeout)
40
- callbacks.each { |cb| cb.remove_and_terminate }
40
+ callbacks.each { |cb| cb.remove_and_terminate if cb.alive? }
41
41
  end
42
42
 
43
43
  raw "NICK :#{nick}"
@@ -1,3 +1,3 @@
1
1
  module Vetinari
2
- VERSION = Gem::Version.new('0.2.1')
2
+ VERSION = Gem::Version.new('0.2.2')
3
3
  end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vetinari::Bot.new do
4
+ subject { Vetinari::Bot.new { |c| c.verbose = false } }
5
+ before(:each) do
6
+ Celluloid.shutdown
7
+ Celluloid.boot
8
+ end
9
+
10
+ it 'terminates all linked actors on termination' do
11
+ expect do
12
+ subject.parse(':server 001 Vetinari :Welcome message')
13
+ subject.parse(':server 376 Vetinari :End of /MOTD command.')
14
+ subject.parse(':Vetinari!foo@bar JOIN #mended_drum')
15
+ subject.parse(':TheLibrarian!foo@bar JOIN #mended_drum')
16
+ subject.terminate
17
+ end.to_not change { Celluloid::Actor.all.size }
18
+ end
19
+
20
+ it 'terminates all linked actors on termination with wild channels' do
21
+ expect do
22
+ subject.parse(':server 001 Vetinari :Welcome message')
23
+ subject.parse(':server 376 Vetinari :End of /MOTD command.')
24
+ subject.parse(':Vetinari!foo@bar JOIN #mended_drum')
25
+ subject.parse(':TheLibrarian!foo@bar JOIN #mended_drum')
26
+ Vetinari::Channel.new('#unseen_university', subject)
27
+ subject.terminate
28
+ end.to_not change { Celluloid::Actor.all.size }
29
+ end
30
+ end
@@ -3,6 +3,10 @@ require 'spec_helper'
3
3
  describe 'Callback' do
4
4
  subject { Vetinari::Bot.new { |c| c.verbose = false } }
5
5
  let(:callbacks) { subject.callbacks.instance_variable_get('@callbacks') }
6
+ before(:each) do
7
+ Celluloid.shutdown
8
+ Celluloid.boot
9
+ end
6
10
 
7
11
  it 'is added correctly' do
8
12
  expect(callbacks[:channel]).to have(1).callback
@@ -4,6 +4,8 @@ describe 'Channel Management' do
4
4
  subject { Vetinari::Bot.new { |c| c.verbose = false } }
5
5
 
6
6
  before(:each) do
7
+ Celluloid.shutdown
8
+ Celluloid.boot
7
9
  subject.parse(':server 001 Vetinari :Welcome message')
8
10
  subject.parse(':server 376 Vetinari :End of /MOTD command.')
9
11
  end
@@ -3,6 +3,10 @@ require 'spec_helper'
3
3
  describe Vetinari::Channel do
4
4
  bot = Vetinari::Bot.new
5
5
  subject { Vetinari::Channel.new('#mended_drum', bot) }
6
+ before(:each) do
7
+ Celluloid.shutdown
8
+ Celluloid.boot
9
+ end
6
10
 
7
11
  it 'responds to #to_s' do
8
12
  expect(subject.to_s).to eq('#mended_drum')
@@ -5,6 +5,8 @@ describe Vetinari::Bot do
5
5
  let(:bare) { subject.bare_object }
6
6
 
7
7
  before(:each) do
8
+ Celluloid.shutdown
9
+ Celluloid.boot
8
10
  subject.parse(':server 001 Vetinari :Welcome message')
9
11
  subject.parse(':server 376 Vetinari :End of /MOTD command.')
10
12
  end
@@ -4,6 +4,8 @@ describe 'Bot#join' do
4
4
  subject { Vetinari::Bot.new { |c| c.verbose = false } }
5
5
 
6
6
  before(:each) do
7
+ Celluloid.shutdown
8
+ Celluloid.boot
7
9
  subject.parse(':server 001 Vetinari :Welcome message')
8
10
  subject.parse(':server 376 Vetinari :End of /MOTD command.')
9
11
  end
@@ -4,6 +4,8 @@ describe 'Bot#rename' do
4
4
  subject { Vetinari::Bot.new { |c| c.verbose = false } }
5
5
 
6
6
  before(:each) do
7
+ Celluloid.shutdown
8
+ Celluloid.boot
7
9
  subject.parse(':server 001 Vetinari :Welcome message')
8
10
  subject.parse(':server 376 Vetinari :End of /MOTD command.')
9
11
  subject.parse(':server 005 Vetinari NICKLEN=10')
@@ -2,6 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe 'User Management' do
4
4
  subject { Vetinari::Bot.new { |c| c.verbose = false } }
5
+ before(:each) do
6
+ Celluloid.shutdown
7
+ Celluloid.boot
8
+ end
5
9
 
6
10
  context 'Connecting to the server' do
7
11
  it 'adds itself to the user_list when connected to the server' do
@@ -3,6 +3,10 @@ require 'spec_helper'
3
3
  describe Vetinari::User do
4
4
  bot = Vetinari::Bot.new
5
5
  subject { Vetinari::User.new('Ridcully', bot) }
6
+ before(:each) do
7
+ Celluloid.shutdown
8
+ Celluloid.boot
9
+ end
6
10
 
7
11
  it 'responds to #to_s' do
8
12
  expect(subject.to_s).to eq('Ridcully')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vetinari
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Bühlmann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-03 00:00:00.000000000 Z
11
+ date: 2013-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid-io
@@ -114,6 +114,7 @@ files:
114
114
  - lib/vetinari/user.rb
115
115
  - lib/vetinari/user_container.rb
116
116
  - lib/vetinari/version.rb
117
+ - spec/bot_spec.rb
117
118
  - spec/callback_spec.rb
118
119
  - spec/channel_management_spec.rb
119
120
  - spec/channel_spec.rb
@@ -150,6 +151,7 @@ signing_key:
150
151
  specification_version: 4
151
152
  summary: Multithreaded IRC Bot Framework.
152
153
  test_files:
154
+ - spec/bot_spec.rb
153
155
  - spec/callback_spec.rb
154
156
  - spec/channel_management_spec.rb
155
157
  - spec/channel_spec.rb