Class: ShootingStar::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/shooting_star/channel.rb

Defined Under Namespace

Classes: InvalidIdError

Constant Summary collapse

@@channels =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Channel

Returns a new instance of Channel.



9
10
11
12
13
14
# File 'lib/shooting_star/channel.rb', line 9

def initialize(path)
  @path = path
  @waiters = Hash.new
  @event_id = 0
  @@channels[path] = self
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/shooting_star/channel.rb', line 6

def path
  @path
end

#waitersObject (readonly)

Returns the value of attribute waiters.



6
7
8
# File 'lib/shooting_star/channel.rb', line 6

def waiters
  @waiters
end

Class Method Details

.[](channel) ⇒ Object



31
# File 'lib/shooting_star/channel.rb', line 31

def self.[](channel); @@channels[channel] end

.cleanup(channel) ⇒ Object



35
36
37
38
39
40
# File 'lib/shooting_star/channel.rb', line 35

def self.cleanup(channel)
  if @@channels[channel] && @@channels[channel].waiters.empty?
    @@channels.delete(channel)
  end
  !@@channels.include?(channel)
end

.listObject



32
# File 'lib/shooting_star/channel.rb', line 32

def self.list; @@channels.keys end

.sweepObject



33
# File 'lib/shooting_star/channel.rb', line 33

def self.sweep; @@channels.delete_if{|k,v| v.waiters.empty?} end

Instance Method Details

#join(server) ⇒ Object



22
23
24
25
# File 'lib/shooting_star/channel.rb', line 22

def join(server)
  @waiters[server.signature] = server
  server.commit
end

#leave(server) ⇒ Object



27
28
29
# File 'lib/shooting_star/channel.rb', line 27

def leave(server)
  @waiters.delete(server.signature)
end

#transmit(id, params) ⇒ Object



16
17
18
19
20
# File 'lib/shooting_star/channel.rb', line 16

def transmit(id, params)
  @waiters.each do |signature, server|
    server.commit if server.respond(id, params)
  end
end