Class: Faye::Channel::Set
- Inherits:
-
Object
- Object
- Faye::Channel::Set
- Defined in:
- lib/faye/protocol/channel.rb
Instance Method Summary (collapse)
- - (Object) distribute_message(message)
- - (Boolean) has_subscription?(name)
-
- (Set) initialize(parent = nil, value = nil)
constructor
A new instance of Set.
- - (Object) keys
- - (Object) remove(name)
- - (Object) subscribe(names, callback)
- - (Object) unsubscribe(name, callback)
Constructor Details
- (Set) initialize(parent = nil, value = nil)
A new instance of Set
77 78 79 |
# File 'lib/faye/protocol/channel.rb', line 77 def initialize(parent = nil, value = nil) @channels = {} end |
Instance Method Details
- (Object) distribute_message(message)
113 114 115 116 117 118 119 |
# File 'lib/faye/protocol/channel.rb', line 113 def () channels = Channel.(['channel']) channels.each do |name| channel = @channels[name] channel.publish_event(:message, ['data']) if channel end end |
- (Boolean) has_subscription?(name)
89 90 91 |
# File 'lib/faye/protocol/channel.rb', line 89 def has_subscription?(name) @channels.has_key?(name) end |
- (Object) keys
81 82 83 |
# File 'lib/faye/protocol/channel.rb', line 81 def keys @channels.keys end |
- (Object) remove(name)
85 86 87 |
# File 'lib/faye/protocol/channel.rb', line 85 def remove(name) @channels.delete(name) end |
- (Object) subscribe(names, callback)
93 94 95 96 97 98 99 |
# File 'lib/faye/protocol/channel.rb', line 93 def subscribe(names, callback) return unless callback names.each do |name| channel = @channels[name] ||= Channel.new(name) channel.add_subscriber(:message, callback) end end |
- (Object) unsubscribe(name, callback)
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/faye/protocol/channel.rb', line 101 def unsubscribe(name, callback) channel = @channels[name] return false unless channel channel.remove_subscriber(:message, callback) if channel.unused? remove(name) true else false end end |