Class: PusherClient::Subscriptions

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSubscriptions

Returns a new instance of Subscriptions.



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

def initialize
  @subscriptions = []
end

Instance Attribute Details

#subscriptionsObject (readonly)

Returns the value of attribute subscriptions.



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

def subscriptions
  @subscriptions
end

Instance Method Details

#add(channel_name, user_data) ⇒ Object Also known as: <<



9
10
11
12
13
14
# File 'lib/pusher-client/subscriptions.rb', line 9

def add(channel_name, user_data)
  unless find(channel_name, user_data)
    @subscriptions << Subscription.new(channel_name, user_data)
  end
  find(channel_name, user_data)
end

#empty?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/pusher-client/subscriptions.rb', line 34

def empty?
  @subscriptions.empty?
end

#find(channel_name, user_data) ⇒ Object



24
25
26
# File 'lib/pusher-client/subscriptions.rb', line 24

def find(channel_name, user_data)
  @subscriptions.detect { |s| s.channel == channel_name && s.user_data == user_data }
end

#find_all(channel_name) ⇒ Object



16
17
18
# File 'lib/pusher-client/subscriptions.rb', line 16

def find_all(channel_name)
  @subscriptions.select {|s| s.channel == channel_name }
end

#find_for_bind(channel_name) ⇒ Object Also known as: []



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

def find_for_bind(channel_name)
  @subscriptions.detect {|s| s.channel == channel_name }
end

#remove(channel_name, user_data) ⇒ Object



28
29
30
31
32
# File 'lib/pusher-client/subscriptions.rb', line 28

def remove(channel_name, user_data)
  subscription = find(channel_name, user_data)
  @subscriptions.delete(subscription)
  @subscriptions
end

#sizeObject



38
39
40
# File 'lib/pusher-client/subscriptions.rb', line 38

def size
  @subscriptions.size
end