celluloid_pubsub 0.0.22 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/celluloid_pubsub.gemspec +3 -3
- data/examples/simple_test.rb +2 -2
- data/lib/celluloid_pubsub/client_pubsub.rb +203 -225
- data/lib/celluloid_pubsub/version.rb +2 -2
- data/spec/lib/celluloid_pubsub/client_pubsub_spec.rb +12 -22
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81bb4bf2f3f59d8e2cea33053a7f89efb5af637d
|
4
|
+
data.tar.gz: 640efba60772877db2fdd2839b1359cc84578b19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70f8af8310490d573cbdb09b457da8695f91a7581e274e6793e0945a3f16a5021cad452f69165d874ae2714fe74d24545c775ed0a61dfaf856630700cd47bf8d
|
7
|
+
data.tar.gz: d4ff8d15ddbf405e136bbc0b17f502dc6ec4843f7e1ac7170711d45f57b3484762b7ed458a89392ed9fd2c330aa2f18fdff41784e7bbd53e8968d86e4de4fe73
|
data/celluloid_pubsub.gemspec
CHANGED
@@ -16,11 +16,11 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.test_files = s.files.grep(/^(spec)/)
|
17
17
|
s.require_paths = ['lib']
|
18
18
|
|
19
|
-
s.add_runtime_dependency 'celluloid', '~> 0.16', '~> 0.16.0'
|
19
|
+
s.add_runtime_dependency 'celluloid', '~> 0.16', '~> 0.16.0' # TODO: upgrade to version 0.17 - work in progress
|
20
20
|
s.add_runtime_dependency 'celluloid-io', '~> 0.16', '>= 0.16.2'
|
21
21
|
s.add_runtime_dependency 'reel', '~> 0.5', '>= 0.5.0'
|
22
|
-
s.add_runtime_dependency 'http', '~> 0.9.8', '>= 0.9.8' # TODO: remove this once fixed in reel gem
|
23
|
-
s.add_runtime_dependency 'celluloid-websocket-client', '0.0.1'
|
22
|
+
s.add_runtime_dependency 'http', '~> 0.9.8', '>= 0.9.8' # TODO: remove this once fixed in reel gem ( waiting for version 0.6.0 of reel to be stable)
|
23
|
+
s.add_runtime_dependency 'celluloid-websocket-client', '~> 0.0', '>= 0.0.1'
|
24
24
|
s.add_runtime_dependency 'activesupport', '~> 4.1', '>= 4.1.0'
|
25
25
|
|
26
26
|
s.add_development_dependency 'rspec-rails', '~> 3.3', '>= 3.3'
|
data/examples/simple_test.rb
CHANGED
@@ -19,7 +19,7 @@ class Subscriber
|
|
19
19
|
include Celluloid::Logger
|
20
20
|
|
21
21
|
def initialize(options = {})
|
22
|
-
@client = CelluloidPubsub::Client.
|
22
|
+
@client = CelluloidPubsub::Client.new({ actor: Actor.current, channel: 'test_channel' }.merge(options))
|
23
23
|
end
|
24
24
|
|
25
25
|
def on_message(message)
|
@@ -44,7 +44,7 @@ class Publisher
|
|
44
44
|
include Celluloid::Logger
|
45
45
|
|
46
46
|
def initialize(options = {})
|
47
|
-
@client = CelluloidPubsub::Client.
|
47
|
+
@client = CelluloidPubsub::Client.new({ actor: Actor.current, channel: 'test_channel2' }.merge(options))
|
48
48
|
@client.publish('test_channel', 'data' => 'my_message') # the message needs to be a Hash
|
49
49
|
end
|
50
50
|
|
@@ -1,254 +1,232 @@
|
|
1
1
|
module CelluloidPubsub
|
2
|
-
#
|
2
|
+
# worker that subscribes to a channel or publishes to a channel
|
3
|
+
# if it used to subscribe to a channel the worker will dispatch the messages to the actor that made the
|
4
|
+
# connection in the first place.
|
5
|
+
#
|
6
|
+
# @!attribute actor
|
7
|
+
# @return [Celluloid::Actor] actor to which callbacks will be delegated to
|
8
|
+
#
|
9
|
+
# @!attribute connect_blk
|
10
|
+
# @return [Proc] Block that will execute after the connection is opened
|
11
|
+
#
|
12
|
+
# @!attribute client
|
13
|
+
# @return [Celluloid::WebSocket::Client] A websocket client that is used to chat witht the webserver
|
14
|
+
#
|
15
|
+
# @!attribute options
|
16
|
+
# @return [Hash] the options that can be used to connect to webser and send additional data
|
17
|
+
#
|
18
|
+
# @!attribute hostname
|
19
|
+
# @return [String] The hostname on which the webserver runs on
|
20
|
+
#
|
21
|
+
# @!attribute port
|
22
|
+
# @return [String] The port on which the webserver runs on
|
23
|
+
#
|
24
|
+
# @!attribute path
|
25
|
+
# @return [String] The hostname on which the webserver runs on
|
3
26
|
class Client
|
4
|
-
|
5
|
-
|
6
|
-
|
27
|
+
include Celluloid
|
28
|
+
include Celluloid::Logger
|
29
|
+
attr_accessor :actor, :client, :options, :hostname, :port, :path, :channel
|
30
|
+
|
31
|
+
# receives a list of options that are used to connect to the webserver and an actor to which the callbacks are delegated to
|
32
|
+
# when receiving messages from a channel
|
7
33
|
#
|
8
|
-
#
|
9
|
-
#
|
34
|
+
# @param [Hash] options the options that can be used to connect to webser and send additional data
|
35
|
+
# @option options [String] :actor The actor that made the connection
|
36
|
+
# @option options [String]:hostname The hostname on which the webserver runs on
|
37
|
+
# @option options [String] :port The port on which the webserver runs on
|
38
|
+
# @option options [String] :path The request path that the webserver accepts
|
10
39
|
#
|
11
|
-
#
|
12
|
-
# @return [Proc] Block that will execute after the connection is opened
|
40
|
+
# @param [Proc] connect_blk Block that will execute after the connection is opened
|
13
41
|
#
|
14
|
-
#
|
15
|
-
# @return [Celluloid::WebSocket::Client] A websocket client that is used to chat witht the webserver
|
42
|
+
# @return [void]
|
16
43
|
#
|
17
|
-
#
|
18
|
-
|
44
|
+
# @api public
|
45
|
+
def initialize(options)
|
46
|
+
parse_options(options)
|
47
|
+
raise "#{self}: Please provide an actor in the options list!!!" if @actor.blank?
|
48
|
+
raise "#{self}: Please provide an channel in the options list!!!" if @channel.blank?
|
49
|
+
@client = Celluloid::WebSocket::Client.new("ws://#{@hostname}:#{@port}#{@path}", Actor.current)
|
50
|
+
end
|
51
|
+
|
52
|
+
# check the options list for values and sets default values if not found
|
19
53
|
#
|
20
|
-
#
|
21
|
-
#
|
54
|
+
# @param [Hash] options the options that can be used to connect to webser and send additional data
|
55
|
+
# @option options [String] :actor The actor that made the connection
|
56
|
+
# @option options [String]:hostname The hostname on which the webserver runs on
|
57
|
+
# @option options [String] :port The port on which the webserver runs on
|
58
|
+
# @option options [String] :path The request path that the webserver accepts
|
22
59
|
#
|
23
|
-
#
|
24
|
-
# @return [String] The port on which the webserver runs on
|
60
|
+
# @return [void]
|
25
61
|
#
|
26
|
-
#
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
# @param [Hash] options the options that can be used to connect to webser and send additional data
|
37
|
-
# @option options [String] :actor The actor that made the connection
|
38
|
-
# @option options [String]:hostname The hostname on which the webserver runs on
|
39
|
-
# @option options [String] :port The port on which the webserver runs on
|
40
|
-
# @option options [String] :path The request path that the webserver accepts
|
41
|
-
#
|
42
|
-
# @param [Proc] connect_blk Block that will execute after the connection is opened
|
43
|
-
#
|
44
|
-
# @return [void]
|
45
|
-
#
|
46
|
-
# @api public
|
47
|
-
def initialize(options)
|
48
|
-
parse_options(options)
|
49
|
-
raise "#{self}: Please provide an actor in the options list!!!" if @actor.blank?
|
50
|
-
raise "#{self}: Please provide an channel in the options list!!!" if @channel.blank?
|
51
|
-
@client = Celluloid::WebSocket::Client.new("ws://#{@hostname}:#{@port}#{@path}", Actor.current)
|
52
|
-
end
|
53
|
-
|
54
|
-
# check the options list for values and sets default values if not found
|
55
|
-
#
|
56
|
-
# @param [Hash] options the options that can be used to connect to webser and send additional data
|
57
|
-
# @option options [String] :actor The actor that made the connection
|
58
|
-
# @option options [String]:hostname The hostname on which the webserver runs on
|
59
|
-
# @option options [String] :port The port on which the webserver runs on
|
60
|
-
# @option options [String] :path The request path that the webserver accepts
|
61
|
-
#
|
62
|
-
# @return [void]
|
63
|
-
#
|
64
|
-
# @api public
|
65
|
-
def parse_options(options)
|
66
|
-
raise 'Options is not a hash' unless options.is_a?(Hash)
|
67
|
-
@options = options.stringify_keys!
|
68
|
-
@actor = @options.fetch('actor', nil)
|
69
|
-
@channel = @options.fetch('channel', nil)
|
70
|
-
@hostname = @options.fetch('hostname', CelluloidPubsub::WebServer::HOST)
|
71
|
-
@port = @options.fetch('port', CelluloidPubsub::WebServer::PORT)
|
72
|
-
@path = @options.fetch('path', CelluloidPubsub::WebServer::PATH)
|
73
|
-
end
|
74
|
-
|
75
|
-
# checks if debug is enabled
|
76
|
-
#
|
77
|
-
#
|
78
|
-
# @return [boolean]
|
79
|
-
#
|
80
|
-
# @api public
|
81
|
-
def debug_enabled?
|
82
|
-
@options.fetch('enable_debug', false).to_s == 'true'
|
83
|
-
end
|
62
|
+
# @api public
|
63
|
+
def parse_options(options)
|
64
|
+
raise 'Options is not a hash' unless options.is_a?(Hash)
|
65
|
+
@options = options.stringify_keys!
|
66
|
+
@actor = @options.fetch('actor', nil)
|
67
|
+
@channel = @options.fetch('channel', nil)
|
68
|
+
@hostname = @options.fetch('hostname', CelluloidPubsub::WebServer::HOST)
|
69
|
+
@port = @options.fetch('port', CelluloidPubsub::WebServer::PORT)
|
70
|
+
@path = @options.fetch('path', CelluloidPubsub::WebServer::PATH)
|
71
|
+
end
|
84
72
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
debug("#{self.class} tries to subscribe #{subscription_data}") if debug_enabled?
|
95
|
-
async.chat(subscription_data)
|
96
|
-
end
|
73
|
+
# checks if debug is enabled
|
74
|
+
#
|
75
|
+
#
|
76
|
+
# @return [boolean]
|
77
|
+
#
|
78
|
+
# @api public
|
79
|
+
def debug_enabled?
|
80
|
+
@options.fetch('enable_debug', false).to_s == 'true'
|
81
|
+
end
|
97
82
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
83
|
+
# subscribes to a channel . need to be used inside the connect block passed to the actor
|
84
|
+
#
|
85
|
+
# @param [string] channel
|
86
|
+
#
|
87
|
+
# @return [void]
|
88
|
+
#
|
89
|
+
# @api public
|
90
|
+
def subscribe(channel)
|
91
|
+
subscription_data = { 'client_action' => 'subscribe', 'channel' => channel }
|
92
|
+
debug("#{self.class} tries to subscribe #{subscription_data}") if debug_enabled?
|
93
|
+
async.chat(subscription_data)
|
94
|
+
end
|
108
95
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
end
|
96
|
+
# checks if the message has the successfull subscription action
|
97
|
+
#
|
98
|
+
# @param [string] message
|
99
|
+
#
|
100
|
+
# @return [void]
|
101
|
+
#
|
102
|
+
# @api public
|
103
|
+
def succesfull_subscription?(message)
|
104
|
+
message.present? && message['client_action'].present? && message['client_action'] == 'successful_subscription'
|
105
|
+
end
|
120
106
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
107
|
+
# publishes to a channel some data (can be anything)
|
108
|
+
#
|
109
|
+
# @param [string] channel
|
110
|
+
# @param [#to_s] data
|
111
|
+
#
|
112
|
+
# @return [void]
|
113
|
+
#
|
114
|
+
# @api public
|
115
|
+
def publish(channel, data)
|
116
|
+
send_action('publish', channel, data)
|
117
|
+
end
|
131
118
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
119
|
+
# unsubscribes current client from a channel
|
120
|
+
#
|
121
|
+
# @param [string] channel
|
122
|
+
#
|
123
|
+
# @return [void]
|
124
|
+
#
|
125
|
+
# @api public
|
126
|
+
def unsubscribe(channel)
|
127
|
+
send_action('unsubscribe', channel)
|
128
|
+
end
|
142
129
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
130
|
+
# unsubscribes all clients subscribed to a channel
|
131
|
+
#
|
132
|
+
# @param [string] channel
|
133
|
+
#
|
134
|
+
# @return [void]
|
135
|
+
#
|
136
|
+
# @api public
|
137
|
+
def unsubscribe_clients(channel)
|
138
|
+
send_action('unsubscribe_clients', channel)
|
139
|
+
end
|
151
140
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
end
|
141
|
+
# unsubscribes all clients from all channels
|
142
|
+
#
|
143
|
+
# @return [void]
|
144
|
+
#
|
145
|
+
# @api public
|
146
|
+
def unsubscribe_all
|
147
|
+
send_action('unsubscribe_all')
|
148
|
+
end
|
161
149
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
#
|
169
|
-
|
170
|
-
|
171
|
-
def on_message(data)
|
172
|
-
debug("#{self.class} received plain #{data}") if debug_enabled?
|
173
|
-
message = JSON.parse(data)
|
174
|
-
debug("#{self.class} received JSON #{message}") if debug_enabled?
|
175
|
-
@actor.async.on_message(message)
|
176
|
-
end
|
150
|
+
# callback executes after connection is opened and delegates action to actor
|
151
|
+
#
|
152
|
+
# @return [void]
|
153
|
+
#
|
154
|
+
# @api public
|
155
|
+
def on_open
|
156
|
+
debug("#{self.class} websocket connection opened") if debug_enabled?
|
157
|
+
async.subscribe(@channel)
|
158
|
+
end
|
177
159
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
160
|
+
# callback executes when actor receives a message from a subscribed channel
|
161
|
+
# and parses the message using JSON.parse and dispatches the parsed
|
162
|
+
# message to the original actor that made the connection
|
163
|
+
#
|
164
|
+
# @param [JSON] data
|
165
|
+
#
|
166
|
+
# @return [void]
|
167
|
+
#
|
168
|
+
# @api public
|
169
|
+
def on_message(data)
|
170
|
+
debug("#{self.class} received plain #{data}") if debug_enabled?
|
171
|
+
message = JSON.parse(data)
|
172
|
+
debug("#{self.class} received JSON #{message}") if debug_enabled?
|
173
|
+
@actor.async.on_message(message)
|
174
|
+
end
|
193
175
|
|
194
|
-
|
176
|
+
# callback executes when connection closes
|
177
|
+
#
|
178
|
+
# @param [String] code
|
179
|
+
#
|
180
|
+
# @param [String] reason
|
181
|
+
#
|
182
|
+
# @return [void]
|
183
|
+
#
|
184
|
+
# @api public
|
185
|
+
def on_close(code, reason)
|
186
|
+
@client.terminate
|
187
|
+
terminate
|
188
|
+
debug("#{self.class} dispatching on close #{code} #{reason}") if debug_enabled?
|
189
|
+
@actor.async.on_close(code, reason)
|
190
|
+
end
|
195
191
|
|
196
|
-
|
197
|
-
#
|
198
|
-
# @param [String] action
|
199
|
-
# @param [String] channel
|
200
|
-
# @param [Hash] data
|
201
|
-
#
|
202
|
-
# @return [void]
|
203
|
-
#
|
204
|
-
# @api private
|
205
|
-
def send_action(action, channel = nil, data = {})
|
206
|
-
publishing_data = { 'client_action' => action }
|
207
|
-
publishing_data = publishing_data.merge('channel' => channel) if channel.present?
|
208
|
-
publishing_data = publishing_data.merge('data' => data) if data.present?
|
209
|
-
debug(" #{self.class} sends: #{publishing_data}") if debug_enabled?
|
210
|
-
async.chat(publishing_data)
|
211
|
-
end
|
192
|
+
private
|
212
193
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
text_messsage = JSON.dump(action: 'message', message: message)
|
229
|
-
debug("#{self.class} sends JSON #{text_messsage}") if debug_enabled?
|
230
|
-
final_message = text_messsage
|
231
|
-
end
|
232
|
-
@client.text final_message
|
233
|
-
end
|
194
|
+
# method used to send an action to the webserver reactor , to a chanel and with data
|
195
|
+
#
|
196
|
+
# @param [String] action
|
197
|
+
# @param [String] channel
|
198
|
+
# @param [Hash] data
|
199
|
+
#
|
200
|
+
# @return [void]
|
201
|
+
#
|
202
|
+
# @api private
|
203
|
+
def send_action(action, channel = nil, data = {})
|
204
|
+
publishing_data = { 'client_action' => action }
|
205
|
+
publishing_data = publishing_data.merge('channel' => channel) if channel.present?
|
206
|
+
publishing_data = publishing_data.merge('data' => data) if data.present?
|
207
|
+
debug(" #{self.class} sends: #{publishing_data}") if debug_enabled?
|
208
|
+
async.chat(publishing_data)
|
234
209
|
end
|
235
210
|
|
236
|
-
# method used to
|
237
|
-
#
|
211
|
+
# method used to send messages to the webserver
|
212
|
+
# checks too see if the message is a hash and if it is it will transform it to JSON and send it to the webser
|
213
|
+
# otherwise will construct a JSON object that will have the key action with the value 'message" and the key message witth the parameter's value
|
238
214
|
#
|
239
|
-
# @param
|
240
|
-
# @option options [String] :actor The actor that made the connection
|
241
|
-
# @option options [String]:hostname The hostname on which the webserver runs on
|
242
|
-
# @option options [String] :port The port on which the webserver runs on
|
243
|
-
# @option options [String] :path The request path that the webserver accepts
|
244
|
-
#
|
245
|
-
# @param [Proc] connect_blk Block that will execute after the connection is opened
|
215
|
+
# @param [Hash] message
|
246
216
|
#
|
247
|
-
# @return [
|
217
|
+
# @return [void]
|
248
218
|
#
|
249
|
-
# @api
|
250
|
-
def
|
251
|
-
|
219
|
+
# @api private
|
220
|
+
def chat(message)
|
221
|
+
final_message = nil
|
222
|
+
if message.is_a?(Hash)
|
223
|
+
final_message = message.to_json
|
224
|
+
debug("#{self.class} sends #{message.to_json}") if debug_enabled?
|
225
|
+
else
|
226
|
+
final_message = JSON.dump(action: 'message', message: message)
|
227
|
+
debug("#{self.class} sends JSON #{final_message}") if debug_enabled?
|
228
|
+
end
|
229
|
+
@client.text final_message
|
252
230
|
end
|
253
231
|
end
|
254
232
|
end
|
@@ -3,32 +3,23 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe CelluloidPubsub::Client do
|
6
|
-
let(:options) { {} }
|
7
|
-
let(:blk) { proc { |a| puts a } }
|
8
|
-
|
9
|
-
it 'runs the connect method' do
|
10
|
-
expected = nil
|
11
|
-
CelluloidPubsub::Client::PubSubWorker.stubs(:new).returns(expected)
|
12
|
-
res = CelluloidPubsub::Client.connect(options, &blk)
|
13
|
-
expect(res).to eq expected
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe CelluloidPubsub::Client::PubSubWorker do
|
18
6
|
let(:blk) { proc { |a| puts a } }
|
19
7
|
let(:options) { {} }
|
20
8
|
let(:socket) { mock }
|
21
9
|
let(:actor) { mock }
|
10
|
+
let(:connection) { mock }
|
22
11
|
let(:channel) { 'some_channel' }
|
23
12
|
|
24
13
|
before(:each) do
|
25
|
-
Celluloid::WebSocket::Client.stubs(:new).returns(
|
26
|
-
|
27
|
-
@worker = CelluloidPubsub::Client::PubSubWorker.new({ 'actor' => actor, channel: channel, enable_debug: true }, &blk)
|
14
|
+
Celluloid::WebSocket::Client.stubs(:new).returns(connection)
|
15
|
+
@worker = CelluloidPubsub::Client.new({ 'actor' => actor, channel: channel, enable_debug: true }, &blk)
|
28
16
|
@worker.stubs(:client).returns(socket)
|
29
|
-
@worker.stubs(:debug)
|
17
|
+
@worker.stubs(:debug).returns(true)
|
30
18
|
@worker.stubs(:async).returns(@worker)
|
31
19
|
actor.stubs(:async).returns(actor)
|
20
|
+
socket.stubs(:terminate).returns(true)
|
21
|
+
connection.stubs(:terminate).returns(true)
|
22
|
+
connection.stubs(:text).returns(true)
|
32
23
|
end
|
33
24
|
|
34
25
|
describe '#initialize' do
|
@@ -132,12 +123,11 @@ describe CelluloidPubsub::Client::PubSubWorker do
|
|
132
123
|
|
133
124
|
describe '#on_close' do
|
134
125
|
let(:channel) { 'some_channel' }
|
135
|
-
let(:code) { '
|
136
|
-
let(:reason) { '
|
126
|
+
let(:code) { 'some_code' }
|
127
|
+
let(:reason) { 'some_reason' }
|
137
128
|
|
138
129
|
it 'chats with the server' do
|
139
|
-
|
140
|
-
@worker.actor.expects(:on_close).with(code, reason)
|
130
|
+
actor.expects(:on_close).with(code, reason).returns(true)
|
141
131
|
@worker.on_close(code, reason)
|
142
132
|
end
|
143
133
|
end
|
@@ -149,12 +139,12 @@ describe CelluloidPubsub::Client::PubSubWorker do
|
|
149
139
|
let(:json) { { action: 'message', message: data } }
|
150
140
|
it 'chats witout hash' do
|
151
141
|
JSON.expects(:dump).with(json).returns(json)
|
152
|
-
|
142
|
+
connection.expects(:text).with(json)
|
153
143
|
@worker.send(:chat, data)
|
154
144
|
end
|
155
145
|
|
156
146
|
it 'chats with a hash' do
|
157
|
-
|
147
|
+
connection.expects(:text).with(data_hash.to_json)
|
158
148
|
@worker.send(:chat, data_hash)
|
159
149
|
end
|
160
150
|
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: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bogdanRada
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid
|
@@ -94,14 +94,20 @@ dependencies:
|
|
94
94
|
name: celluloid-websocket-client
|
95
95
|
requirement: !ruby/object:Gem::Requirement
|
96
96
|
requirements:
|
97
|
-
- -
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0.0'
|
100
|
+
- - ">="
|
98
101
|
- !ruby/object:Gem::Version
|
99
102
|
version: 0.0.1
|
100
103
|
type: :runtime
|
101
104
|
prerelease: false
|
102
105
|
version_requirements: !ruby/object:Gem::Requirement
|
103
106
|
requirements:
|
104
|
-
- -
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0.0'
|
110
|
+
- - ">="
|
105
111
|
- !ruby/object:Gem::Version
|
106
112
|
version: 0.0.1
|
107
113
|
- !ruby/object:Gem::Dependency
|