Class: PusherClient::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/pusher-client/channel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel_name) ⇒ Channel

Returns a new instance of Channel.



6
7
8
9
10
11
12
# File 'lib/pusher-client/channel.rb', line 6

def initialize(channel_name)
  @name = channel_name
  @global = false
  @callbacks = {}
  @global_callbacks = {}
  @subscribed = false
end

Instance Attribute Details

#callbacksObject (readonly)

Returns the value of attribute callbacks.



4
5
6
# File 'lib/pusher-client/channel.rb', line 4

def callbacks
  @callbacks
end

#globalObject

Returns the value of attribute global.



3
4
5
# File 'lib/pusher-client/channel.rb', line 3

def global
  @global
end

#global_callbacksObject (readonly)

Returns the value of attribute global_callbacks.



4
5
6
# File 'lib/pusher-client/channel.rb', line 4

def global_callbacks
  @global_callbacks
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/pusher-client/channel.rb', line 4

def name
  @name
end

#subscribedObject

Returns the value of attribute subscribed.



3
4
5
# File 'lib/pusher-client/channel.rb', line 3

def subscribed
  @subscribed
end

Instance Method Details

#acknowledge_subscription(data) ⇒ Object



47
48
49
# File 'lib/pusher-client/channel.rb', line 47

def acknowledge_subscription(data)
  @subscribed = true
end

#bind(event_name, &callback) ⇒ Object



14
15
16
17
18
# File 'lib/pusher-client/channel.rb', line 14

def bind(event_name, &callback)
  @callbacks[event_name] = callbacks[event_name] || []
  @callbacks[event_name] << callback
  return self
end

#dispatch(event_name, data) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/pusher-client/channel.rb', line 25

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



36
37
38
39
40
41
42
43
44
45
# File 'lib/pusher-client/channel.rb', line 36

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



20
21
22
23
# File 'lib/pusher-client/channel.rb', line 20

def dispatch_with_all(event_name, data)
  dispatch(event_name, data)
  dispatch_global_callbacks(event_name, data)
end