Class: Nuge::Pusher

Inherits:
Object
  • Object
show all
Defined in:
lib/nuge/pusher.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(clients = nil) ⇒ Pusher

Returns a new instance of Pusher.



16
17
18
# File 'lib/nuge/pusher.rb', line 16

def initialize(clients = nil)
  @clients = Set.new(clients || self.class.clients)
end

Instance Attribute Details

#clientsObject (readonly)

Returns the value of attribute clients.



13
14
15
# File 'lib/nuge/pusher.rb', line 13

def clients
  @clients
end

#expanderObject



32
33
34
# File 'lib/nuge/pusher.rb', line 32

def expander
  @expander ||= -> (obj) { obj }
end

Class Method Details

.clientsObject



9
10
11
# File 'lib/nuge/pusher.rb', line 9

def self.clients
  @clients ||= Set.new
end

.clients=(clients) ⇒ Object



5
6
7
# File 'lib/nuge/pusher.rb', line 5

def self.clients=(clients)
  @clients = Set.new(clients)
end

Instance Method Details

#expanded(*objects) ⇒ Object



36
37
38
# File 'lib/nuge/pusher.rb', line 36

def expanded(*objects)
  objects.flatten.map { |obj| expander.call(obj) }
end

#push(ids, message) ⇒ Object



20
21
22
# File 'lib/nuge/pusher.rb', line 20

def push(ids, message)
  clients.each { |client| client.push(expanded(ids), message) }
end

#register(id, options = {}) ⇒ Object



24
25
26
# File 'lib/nuge/pusher.rb', line 24

def register(id, options = {})
  clients.each { |client| client.register(expanded(id).first, options) }
end

#unregister(id, options = {}) ⇒ Object



28
29
30
# File 'lib/nuge/pusher.rb', line 28

def unregister(id, options = {})
  clients.each { |client| client.unregister(expanded(id).first, options) }
end