Class: PusherClient::Channel
- Inherits:
-
Object
- Object
- PusherClient::Channel
- Defined in:
- lib/pusher-client/channel.rb
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
readonly
Returns the value of attribute callbacks.
-
#global ⇒ Object
Returns the value of attribute global.
-
#global_callbacks ⇒ Object
readonly
Returns the value of attribute global_callbacks.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#subscribed ⇒ Object
Returns the value of attribute subscribed.
Instance Method Summary collapse
- #acknowledge_subscription(data) ⇒ Object
- #bind(event_name, &callback) ⇒ Object
- #dispatch(event_name, data) ⇒ Object
- #dispatch_global_callbacks(event_name, data) ⇒ Object
- #dispatch_with_all(event_name, data) ⇒ Object
-
#initialize(channel_name) ⇒ Channel
constructor
A new instance of Channel.
Constructor Details
#initialize(channel_name) ⇒ Channel
Returns a new instance of Channel.
7 8 9 10 11 12 13 |
# File 'lib/pusher-client/channel.rb', line 7 def initialize(channel_name) @name = channel_name @global = false @callbacks = {} @global_callbacks = {} @subscribed = false end |
Instance Attribute Details
#callbacks ⇒ Object (readonly)
Returns the value of attribute callbacks.
5 6 7 |
# File 'lib/pusher-client/channel.rb', line 5 def callbacks @callbacks end |
#global ⇒ Object
Returns the value of attribute global.
4 5 6 |
# File 'lib/pusher-client/channel.rb', line 4 def global @global end |
#global_callbacks ⇒ Object (readonly)
Returns the value of attribute global_callbacks.
5 6 7 |
# File 'lib/pusher-client/channel.rb', line 5 def global_callbacks @global_callbacks end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/pusher-client/channel.rb', line 5 def name @name end |
#subscribed ⇒ Object
Returns the value of attribute subscribed.
4 5 6 |
# File 'lib/pusher-client/channel.rb', line 4 def subscribed @subscribed end |
Instance Method Details
#acknowledge_subscription(data) ⇒ Object
48 49 50 |
# File 'lib/pusher-client/channel.rb', line 48 def acknowledge_subscription(data) @subscribed = true end |
#bind(event_name, &callback) ⇒ Object
15 16 17 18 19 |
# File 'lib/pusher-client/channel.rb', line 15 def bind(event_name, &callback) @callbacks[event_name] = callbacks[event_name] || [] @callbacks[event_name] << callback return self end |
#dispatch(event_name, data) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/pusher-client/channel.rb', line 26 def dispatch(event_name, data) PusherClient.logger.debug "Dispatching callbacks for #{event_name}" if @callbacks[event_name] @callbacks[event_name].each do |callback| callback.call(data) end else PusherClient.logger.debug "No callbacks to dispatch for #{event_name}" end end |
#dispatch_global_callbacks(event_name, data) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pusher-client/channel.rb', line 37 def dispatch_global_callbacks(event_name, data) if @global_callbacks[event_name] PusherClient.logger.debug "Dispatching global callbacks for #{event_name}" @global_callbacks[event_name].each do |callback| callback.call(data) end else PusherClient.logger.debug "No global callbacks to dispatch for #{event_name}" end end |
#dispatch_with_all(event_name, data) ⇒ Object
21 22 23 24 |
# File 'lib/pusher-client/channel.rb', line 21 def dispatch_with_all(event_name, data) dispatch(event_name, data) dispatch_global_callbacks(event_name, data) end |