simplepubsub 1.0.4 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9cff3810ef87030f5a6a312619116f350b0dac8d
4
- data.tar.gz: 6cda858da272e52b3963db0fc2a2640a94b6dcda
3
+ metadata.gz: 8e5c822fc449cb17e0be9b54fd7983047dcf25c7
4
+ data.tar.gz: be521eac2afbce4ad9a7d3aaf7741025bbf89f5e
5
5
  SHA512:
6
- metadata.gz: c26f81f94e81f30a699bdc0bd262aa525d8800fe745218d719dbd3d2115797196e5114af8aba5e9dd87ce13942457897ea79bca3dbdaad06437bbdcaa3071af6
7
- data.tar.gz: d8a02e1983bbd63a4c3b5362b7d2400ed124f0876355f30db7837ce60fb115378e0f329d63dbbb3fd9a9b6e146f1c24a268dec4b241c1ca896cc1cf6142359f1
6
+ metadata.gz: dd64f0bc0f6def5d6d8d6eb2d6d281f29ad7167ec635aef451fd80f637345569d5f8fc0afb9b321d05a2a130ef00839f8b001c07fae49498401d0efbc117bac1
7
+ data.tar.gz: 3a1bea9cb8a20c1e572fb7969b77ba36ba16df990e64663d4c097c6cdbe7654df2d891e02ed893efed5fe83164fef1fd5916578a3ed4f36fc844755d612b6a24
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/simplepubsub.rb CHANGED
@@ -4,16 +4,15 @@
4
4
 
5
5
  require 'websocket-eventmachine-server'
6
6
  require 'websocket-eventmachine-client'
7
+ require 'xml-registry'
7
8
 
8
9
 
9
10
  module SimplePubSub
10
11
 
11
12
  class Server
12
13
 
13
- def start(options={})
14
+ def start(host: '0.0.0.0', port: 59000)
14
15
 
15
- opt = {host: '0.0.0.0', port: 59000}.merge options
16
- host, port = opt[:host], opt[:port]
17
16
 
18
17
  EM.run do
19
18
 
@@ -37,10 +36,11 @@ module SimplePubSub
37
36
 
38
37
  if a.first == 'subscribe to topic' then
39
38
 
40
- topic = a.last.rstrip
39
+ topic = a.last.rstrip #.gsub('+','*').gsub('#','//')
41
40
  subscribers[topic] ||= []
42
41
  subscribers[topic] << ws
43
42
 
43
+ # affix the topic to the subscriber's websocket
44
44
  def ws.subscriber_topic=(topic) @topic = topic end
45
45
  def ws.subscriber_topic() @topic end
46
46
 
@@ -49,16 +49,25 @@ module SimplePubSub
49
49
  elsif a.length > 1
50
50
 
51
51
  puts "publish this %s: %s" % a
52
- topic, message = a
52
+ current_topic, message = a
53
53
 
54
- if subscribers[topic] then
55
- subscribers[topic].each {|c| c.send topic + ': ' + message }
56
- end
54
+ reg = XMLRegistry.new
55
+ reg[current_topic] = message
57
56
 
58
- if subscribers['#'] then
59
- subscribers['#'].each {|c| c.send topic + ': ' + message }
57
+ subscribers.each do |topic,conns|
58
+ if reg[topic] then
59
+ conns.each {|x| x.send current_topic + ': ' + message}
60
+ end
60
61
  end
61
62
 
63
+ #if subscribers[topic] then
64
+ # subscribers[topic].each {|c| c.send topic + ': ' + message }
65
+ #end
66
+
67
+ #if subscribers['#'] then
68
+ # subscribers['#'].each {|c| c.send topic + ': ' + message }
69
+ #end
70
+
62
71
  #ws.send msg, :type => type
63
72
 
64
73
  end
@@ -96,7 +105,7 @@ module SimplePubSub
96
105
  end
97
106
  end
98
107
 
99
- def self.connect(hostname, port='59000')
108
+ def self.connect(hostname, port='59000', options={})
100
109
 
101
110
  pubsub = PubSub.new
102
111
  yield(pubsub)
@@ -141,10 +150,13 @@ module SimplePubSub
141
150
  blk.call ws, pubsub, em_already_running = true
142
151
  rescue
143
152
 
144
- EM.run do
145
- ws = c.connect(params)
146
- blk.call(ws, pubsub, em_already_running = false)
153
+ thread = Thread.new do
154
+ EM.run do
155
+ ws = c.connect(params)
156
+ blk.call(ws, pubsub, em_already_running = false)
157
+ end
147
158
  end
159
+ thread.join
148
160
  end
149
161
 
150
162
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplepubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  i0PBE6fLwlIMk8jNNUcX3J1csSMgLNTwE8CwrlSZE8sueHj0pQzICM7lF0gGREO6
32
32
  hQHD0LljU3MusQ==
33
33
  -----END CERTIFICATE-----
34
- date: 2013-11-16 00:00:00.000000000 Z
34
+ date: 2014-05-22 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: websocket-eventmachine-server
@@ -61,6 +61,20 @@ dependencies:
61
61
  - - ">="
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0'
64
+ - !ruby/object:Gem::Dependency
65
+ name: xml-registry
66
+ requirement: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
64
78
  description:
65
79
  email: james@r0bertson.co.uk
66
80
  executables: []
@@ -88,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
102
  version: '0'
89
103
  requirements: []
90
104
  rubyforge_project:
91
- rubygems_version: 2.0.0.rc.2
105
+ rubygems_version: 2.1.11
92
106
  signing_key:
93
107
  specification_version: 4
94
108
  summary: simplepubsub
metadata.gz.sig CHANGED
Binary file