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.



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

#callbacksObject (readonly)

Returns the value of attribute callbacks.



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

def callbacks
  @callbacks
end

#globalObject

Returns the value of attribute global.



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

def global
  @global
end

#global_callbacksObject (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

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#subscribedObject

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