Class: Faye::Channel::Set

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

Instance Method Summary collapse

Constructor Details

#initializeSet

Returns a new instance of Set.



78
79
80
# File 'lib/faye/protocol/channel.rb', line 78

def initialize
  @channels = {}
end

Instance Method Details

#distribute_message(message) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/faye/protocol/channel.rb', line 113

def distribute_message(message)
  channels = Channel.expand(message['channel'])
  channels.each do |name|
    channel = @channels[name]
    channel.trigger(:message, message) if channel
  end
end

#has_subscription?(name) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/faye/protocol/channel.rb', line 90

def has_subscription?(name)
  @channels.has_key?(name)
end

#keysObject



82
83
84
# File 'lib/faye/protocol/channel.rb', line 82

def keys
  @channels.keys
end

#remove(name) ⇒ Object



86
87
88
# File 'lib/faye/protocol/channel.rb', line 86

def remove(name)
  @channels.delete(name)
end

#subscribe(names, subscription) ⇒ Object



94
95
96
97
98
99
# File 'lib/faye/protocol/channel.rb', line 94

def subscribe(names, subscription)
  names.each do |name|
    channel = @channels[name] ||= Channel.new(name)
    channel.bind(:message, &subscription)
  end
end

#unsubscribe(name, subscription) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/faye/protocol/channel.rb', line 101

def unsubscribe(name, subscription)
  channel = @channels[name]
  return false unless channel
  channel.unbind(:message, &subscription)
  if channel.unused?
    remove(name)
    true
  else
    false
  end
end