celluloid_pubsub 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +12 -1
- data/Gemfile +2 -3
- data/gemfiles/celluloid_0.16.0.gemfile +0 -1
- data/gemfiles/celluloid_0.17.3.gemfile +0 -1
- data/lib/celluloid_pubsub/reactor.rb +7 -9
- data/lib/celluloid_pubsub/version.rb +2 -2
- data/spec/lib/celluloid_pubsub/reactor_spec.rb +52 -30
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2205e89d97959a97cb9a4887be58c2633478e1f4
|
4
|
+
data.tar.gz: 7fae7ef47ce0afd1c13caaad16b7d56f7de15246
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e09e51937f275c8eac631cbfe66403810da789bf4062e4e32812fdf54ac5ceb119f3ee2be4357040aa7e3751e56941dbdcd7e414235e6722a8dcffc3321a414
|
7
|
+
data.tar.gz: 9dd88606ce87f7418ab94a9108820833327762f4b4d214057311c6154dc7846237934485f26c387a304974bf785bff395ca67c0e1187d46d2010e16df7c5d223
|
data/.travis.yml
CHANGED
@@ -1,9 +1,20 @@
|
|
1
|
+
language: ruby
|
1
2
|
sudo: false
|
3
|
+
|
2
4
|
cache: bundler
|
3
|
-
|
5
|
+
|
6
|
+
bundler_args: --without test --jobs 3 --retry 3
|
7
|
+
|
4
8
|
before_install:
|
5
9
|
- "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc"
|
6
10
|
- gem install bundler
|
11
|
+
- gem update bundler
|
12
|
+
|
13
|
+
install:
|
14
|
+
- bundle install --path vendor/bundle
|
15
|
+
|
16
|
+
script: bundle exec rake
|
17
|
+
|
7
18
|
rvm:
|
8
19
|
- 2.0.0
|
9
20
|
- 2.1.5
|
data/Gemfile
CHANGED
@@ -147,12 +147,12 @@ module CelluloidPubsub
|
|
147
147
|
#
|
148
148
|
# @api public
|
149
149
|
def handle_parsed_websocket_message(json_data)
|
150
|
-
|
151
|
-
|
150
|
+
data = json_data.is_a?(Hash) ? json_data.stringify_keys : {}
|
151
|
+
if CelluloidPubsub::Reactor::AVAILABLE_ACTIONS.include?(data['client_action'].to_s)
|
152
152
|
log_debug "#{self.class} finds actions for #{json_data}"
|
153
|
-
delegate_action(
|
153
|
+
delegate_action(data) if data['client_action'].present?
|
154
154
|
else
|
155
|
-
handle_unknown_action(json_data)
|
155
|
+
handle_unknown_action(data['channel'], json_data)
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
@@ -179,9 +179,7 @@ module CelluloidPubsub
|
|
179
179
|
#
|
180
180
|
# @api public
|
181
181
|
def delegate_action(json_data)
|
182
|
-
|
183
|
-
return unless CelluloidPubsub::Reactor::AVAILABLE_ACTIONS.include?(client_action)
|
184
|
-
async.send(client_action, channel, json_data)
|
182
|
+
async.send(json_data['client_action'], json_data['channel'], json_data)
|
185
183
|
end
|
186
184
|
|
187
185
|
# the method will delegate the message to the server in an asyncronous way by sending the current actor and the message
|
@@ -357,10 +355,10 @@ module CelluloidPubsub
|
|
357
355
|
# @return [void]
|
358
356
|
#
|
359
357
|
# @api public
|
360
|
-
def unsubscribe_all(_channel,
|
358
|
+
def unsubscribe_all(_channel, json_data)
|
361
359
|
log_debug "#{self.class} runs 'unsubscribe_all' method"
|
362
360
|
CelluloidPubsub::Registry.channels.dup.pmap do |channel|
|
363
|
-
unsubscribe_clients(channel)
|
361
|
+
unsubscribe_clients(channel, json_data)
|
364
362
|
end
|
365
363
|
log_debug 'clearing connections'
|
366
364
|
shutdown
|
@@ -19,10 +19,10 @@ module CelluloidPubsub
|
|
19
19
|
# minor release version
|
20
20
|
MINOR = 0
|
21
21
|
# tiny release version
|
22
|
-
TINY =
|
22
|
+
TINY = 1
|
23
23
|
# prelease version ( set this only if it is a prelease)
|
24
24
|
PRE = nil
|
25
|
-
|
25
|
+
|
26
26
|
# generates the version string
|
27
27
|
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
|
28
28
|
end
|
@@ -80,86 +80,108 @@ describe CelluloidPubsub::Reactor do
|
|
80
80
|
|
81
81
|
describe '#handle_parsed_websocket_message' do
|
82
82
|
it 'handle_websocket_message with a hash' do
|
83
|
-
data = { 'client_action' => '
|
83
|
+
data = { 'client_action' => 'subscribe' }
|
84
84
|
data.expects(:stringify_keys).returns(data)
|
85
85
|
subject.expects(:delegate_action).with(data)
|
86
86
|
subject.handle_parsed_websocket_message(data)
|
87
87
|
end
|
88
88
|
|
89
89
|
it 'handle_websocket_message with something else than a hash' do
|
90
|
-
data = 'some message'
|
91
|
-
subject.expects(:handle_unknown_action).with(data)
|
90
|
+
data = { 'message'=> 'some message' }
|
91
|
+
subject.expects(:handle_unknown_action).with(data['channel'], data)
|
92
92
|
subject.handle_parsed_websocket_message(data)
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
96
|
describe '#delegate_action' do
|
97
|
+
|
98
|
+
before(:each) do
|
99
|
+
subject.stubs(:unsubscribe_clients).returns(true)
|
100
|
+
subject.stubs(:shutdown).returns(true)
|
101
|
+
end
|
102
|
+
|
97
103
|
it 'unsubscribes all' do
|
98
|
-
data = { 'client_action' => 'unsubscribe_all' }
|
99
|
-
subject.expects(:
|
104
|
+
data = { 'client_action' => 'unsubscribe_all', 'channel' => '' }
|
105
|
+
subject.expects(:send).with(data['client_action'], data['channel'], data).returns('bla')
|
100
106
|
subject.delegate_action(data)
|
101
107
|
end
|
102
108
|
|
103
109
|
it 'unsubscribes all' do
|
104
110
|
data = { 'client_action' => 'unsubscribe', 'channel' => 'some channel' }
|
105
|
-
subject.expects(:
|
111
|
+
subject.expects(:send).with(data['client_action'], data['channel'], data)
|
106
112
|
subject.delegate_action(data)
|
107
113
|
end
|
108
|
-
|
114
|
+
#
|
109
115
|
it 'subscribes to channell' do
|
110
116
|
data = { 'client_action' => 'subscribe', 'channel' => 'some channel' }
|
111
|
-
subject.expects(:
|
117
|
+
subject.expects(:send).with(data['client_action'], data['channel'], data)
|
112
118
|
subject.delegate_action(data)
|
113
119
|
end
|
114
120
|
|
115
121
|
it 'publish' do
|
116
122
|
data = { 'client_action' => 'publish', 'channel' => 'some channel', 'data' => 'some data' }
|
117
|
-
subject.expects(:
|
118
|
-
subject.delegate_action(data)
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'handles unknown' do
|
122
|
-
data = { 'client_action' => 'some action', 'channel' => 'some channel' }
|
123
|
-
subject.expects(:handle_unknown_action).with(data)
|
123
|
+
subject.expects(:send).with(data['client_action'], data['channel'], data)
|
124
124
|
subject.delegate_action(data)
|
125
125
|
end
|
126
126
|
end
|
127
|
-
|
127
|
+
#
|
128
128
|
describe '#handle_unknown_action' do
|
129
129
|
it 'handles unknown' do
|
130
130
|
data = 'some data'
|
131
|
+
channel = "some_channel"
|
131
132
|
server.expects(:handle_dispatched_message)
|
132
|
-
subject.handle_unknown_action(data)
|
133
|
+
subject.handle_unknown_action(channel, data)
|
133
134
|
end
|
134
135
|
end
|
135
136
|
|
136
137
|
describe '#unsubscribe_client' do
|
137
138
|
let(:channel) { 'some channel' }
|
139
|
+
let(:data) { {'client_action' => 'unsubscribe', 'channel' => channel } }
|
138
140
|
it 'returns nil' do
|
139
|
-
act = subject.unsubscribe('')
|
141
|
+
act = subject.unsubscribe('', data)
|
140
142
|
expect(act).to eq(nil)
|
141
143
|
end
|
142
144
|
|
143
145
|
it 'unsubscribes' do
|
144
|
-
|
145
|
-
subject.
|
146
|
-
|
146
|
+
channel.stubs(:present?).returns(true)
|
147
|
+
subject.expects(:forget_channel).with(channel)
|
148
|
+
subject.expects(:delete_server_subscribers).with(channel)
|
149
|
+
act = subject.unsubscribe(channel, data)
|
147
150
|
expect(act).to eq(nil)
|
148
151
|
end
|
149
152
|
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
describe '#delete_server_subscribers' do
|
157
|
+
let(:channel) { 'some channel' }
|
158
|
+
|
159
|
+
before(:each) do
|
160
|
+
server.stubs(:subscribers).returns("#{channel}" => [{ reactor: subject }])
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'unsubscribes' do
|
164
|
+
act = subject.delete_server_subscribers(channel)
|
165
|
+
expect(server.subscribers[channel]).to eq([])
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe '#forget_channel' do
|
170
|
+
let(:channel) { 'some channel' }
|
171
|
+
|
150
172
|
it 'unsubscribes' do
|
151
173
|
subject.channels.stubs(:blank?).returns(true)
|
152
174
|
subject.websocket.expects(:close)
|
153
|
-
act = subject.
|
175
|
+
act = subject.forget_channel(channel)
|
154
176
|
expect(act).to eq(nil)
|
155
177
|
end
|
156
178
|
|
157
179
|
it 'unsubscribes' do
|
158
180
|
subject.channels.stubs(:blank?).returns(false)
|
159
|
-
subject.channels.
|
160
|
-
|
161
|
-
subject.
|
162
|
-
|
181
|
+
subject.channels.expects(:delete).with(channel)
|
182
|
+
# server.stubs(:subscribers).returns("#{channel}" => [{ reactor: subject }])
|
183
|
+
subject.forget_channel(channel)
|
184
|
+
# expect(server.subscribers[channel]).to eq([])
|
163
185
|
end
|
164
186
|
end
|
165
187
|
|
@@ -175,7 +197,7 @@ describe CelluloidPubsub::Reactor do
|
|
175
197
|
let(:message) { { a: 'b' } }
|
176
198
|
|
177
199
|
it 'subscribes ' do
|
178
|
-
act = subject.
|
200
|
+
act = subject.subscribe('', message)
|
179
201
|
expect(act).to eq(nil)
|
180
202
|
end
|
181
203
|
|
@@ -183,7 +205,7 @@ describe CelluloidPubsub::Reactor do
|
|
183
205
|
subject.stubs(:add_subscriber_to_channel).with(channel, message)
|
184
206
|
server.stubs(:redis_enabled?).returns(false)
|
185
207
|
subject.websocket.expects(:<<).with(message.merge('client_action' => 'successful_subscription', 'channel' => channel).to_json)
|
186
|
-
subject.
|
208
|
+
subject.subscribe(channel, message)
|
187
209
|
end
|
188
210
|
|
189
211
|
# it 'raises error' do
|
@@ -218,8 +240,8 @@ describe CelluloidPubsub::Reactor do
|
|
218
240
|
|
219
241
|
it 'adds subscribed' do
|
220
242
|
CelluloidPubsub::Registry.stubs(:channels).returns([channel])
|
221
|
-
subject.expects(:unsubscribe_from_channel).with(channel)
|
222
|
-
subject.unsubscribe_all
|
243
|
+
subject.expects(:unsubscribe_from_channel).with(channel).returns(true)
|
244
|
+
subject.unsubscribe_all(channel, message)
|
223
245
|
end
|
224
246
|
end
|
225
247
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: celluloid_pubsub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bogdanRada
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid
|