broadcast-objects 0.0.0 → 0.0.1

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.
Files changed (2) hide show
  1. data/lib/broadcast-objects.rb +6 -0
  2. metadata +1 -1
@@ -1,7 +1,9 @@
1
+ #Class for organizing broadcasts.
1
2
  class Channel
2
3
  def initialize
3
4
  @subscribers = []
4
5
  end
6
+ #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
5
7
  def broadcast data
6
8
  for i in subscribers
7
9
  subscribers.recieve(self, data)
@@ -9,13 +11,17 @@ class Channel
9
11
  end
10
12
  attr_accessor :subscribers
11
13
  end
14
+ #Basic module that implements the methods for subscribing and sending broadcasts. functionality for dealing with recieved broadcasts should be implemented by individual classes
12
15
  module Broadcasting
16
+ #Subscribe to channel. While subscribed, will recieve message whenever another objects sends one on that channel.
13
17
  def subscribe channel
14
18
  channel.subscribers.push self
15
19
  end
20
+ #send message to all objects that subscribed to channel, with data.
16
21
  def send(channel, data)
17
22
  channel.broadcast data
18
23
  end
24
+ #Included here for debug purposes, but really should be implemented by each class individually. Called whenever a message is sent on a channel this object subscribed to. Channel is the channel in question, data is the data sent
19
25
  def recieve(channel, data)
20
26
  #always override in child class. Here for debug purposes
21
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"
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.0.0
4
+ version: 0.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: