Class: PusherClient::Subscription
- Inherits:
-
Object
- Object
- PusherClient::Subscription
- Defined in:
- lib/pusher-client/subscription.rb
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
readonly
Returns the value of attribute callbacks.
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#global ⇒ Object
Returns the value of attribute global.
-
#global_callbacks ⇒ Object
readonly
Returns the value of attribute global_callbacks.
-
#subscribed ⇒ Object
Returns the value of attribute subscribed.
-
#user_data ⇒ Object
readonly
Returns the value of attribute user_data.
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, user_data) ⇒ Subscription
constructor
A new instance of Subscription.
Constructor Details
#initialize(channel_name, user_data) ⇒ Subscription
Returns a new instance of Subscription.
6 7 8 9 10 11 12 13 |
# File 'lib/pusher-client/subscription.rb', line 6 def initialize(channel_name, user_data) @channel = channel_name @user_data = user_data @global = false @callbacks = {} @global_callbacks = {} @subscribed = false end |
Instance Attribute Details
#callbacks ⇒ Object (readonly)
Returns the value of attribute callbacks.
4 5 6 |
# File 'lib/pusher-client/subscription.rb', line 4 def callbacks @callbacks end |
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
4 5 6 |
# File 'lib/pusher-client/subscription.rb', line 4 def channel @channel end |
#global ⇒ Object
Returns the value of attribute global.
3 4 5 |
# File 'lib/pusher-client/subscription.rb', line 3 def global @global end |
#global_callbacks ⇒ Object (readonly)
Returns the value of attribute global_callbacks.
4 5 6 |
# File 'lib/pusher-client/subscription.rb', line 4 def global_callbacks @global_callbacks end |
#subscribed ⇒ Object
Returns the value of attribute subscribed.
3 4 5 |
# File 'lib/pusher-client/subscription.rb', line 3 def subscribed @subscribed end |
#user_data ⇒ Object (readonly)
Returns the value of attribute user_data.
4 5 6 |
# File 'lib/pusher-client/subscription.rb', line 4 def user_data @user_data end |
Instance Method Details
#acknowledge_subscription(data) ⇒ Object
48 49 50 |
# File 'lib/pusher-client/subscription.rb', line 48 def acknowledge_subscription(data) @subscribed = true end |
#bind(event_name, &callback) ⇒ Object
15 16 17 18 19 |
# File 'lib/pusher-client/subscription.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/subscription.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/subscription.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/subscription.rb', line 21 def dispatch_with_all(event_name, data) dispatch(event_name, data) dispatch_global_callbacks(event_name, data) end |