broadcast-objects 0.0.1 → 0.1.3
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.
- data/lib/broadcast-objects.rb +10 -10
- metadata +3 -3
data/lib/broadcast-objects.rb
CHANGED
@@ -2,28 +2,28 @@
|
|
2
2
|
class Channel
|
3
3
|
def initialize
|
4
4
|
@subscribers = []
|
5
|
+
@methods = []
|
5
6
|
end
|
6
7
|
#Called when a Broadcasting object sends a broadcast on this channel. Calls the recieve method of all objects subscribing to this channel, passing the channel itself and the data sent as arguments
|
7
8
|
def broadcast data
|
8
|
-
|
9
|
-
|
9
|
+
out = []
|
10
|
+
for i in methods
|
11
|
+
out.push(i.call(data))
|
10
12
|
end
|
13
|
+
return out
|
11
14
|
end
|
12
|
-
attr_accessor :subscribers
|
15
|
+
attr_accessor :subscribers, :methods
|
13
16
|
end
|
14
17
|
#Basic module that implements the methods for subscribing and sending broadcasts. functionality for dealing with recieved broadcasts should be implemented by individual classes
|
15
18
|
module Broadcasting
|
16
19
|
#Subscribe to channel. While subscribed, will recieve message whenever another objects sends one on that channel.
|
17
|
-
|
20
|
+
#methSymbol should be a symbol or string corresponding to the method with which to recieve messaged from that channel.
|
21
|
+
def subscribe(channel, methSymbol)
|
18
22
|
channel.subscribers.push self
|
23
|
+
channel.methods.push self.method(methSymbol)
|
19
24
|
end
|
20
25
|
#send message to all objects that subscribed to channel, with data.
|
21
26
|
def send(channel, data)
|
22
27
|
channel.broadcast data
|
23
28
|
end
|
24
|
-
|
25
|
-
def recieve(channel, data)
|
26
|
-
#always override in child class. Here for debug purposes
|
27
|
-
puts (data.to_s)+" was sent on channel "+(channel.to_s)+" and recieved by object "+(self.to_s)+" which did not implement the recieve function. Something is probably wrong"
|
28
|
-
end
|
29
|
-
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: broadcast-objects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-15 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! "broadcast-objects is a small gem that enables mass communication between
|
15
15
|
objects. While this is usually restricted to communication to a singular\n\tobject,
|
@@ -41,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
41
|
version: '0'
|
42
42
|
requirements: []
|
43
43
|
rubyforge_project:
|
44
|
-
rubygems_version: 1.8.
|
44
|
+
rubygems_version: 1.8.24
|
45
45
|
signing_key:
|
46
46
|
specification_version: 3
|
47
47
|
summary: Simple system to let objects communicate en masse
|