Class: RenderSync::Clients::Pusher::Message

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel, data) ⇒ Message

Returns a new instance of Message.



52
53
54
55
# File 'lib/render_sync/clients/pusher.rb', line 52

def initialize(channel, data)
  self.channel = channel
  self.data = data
end

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



44
45
46
# File 'lib/render_sync/clients/pusher.rb', line 44

def channel
  @channel
end

#dataObject

Returns the value of attribute data.



44
45
46
# File 'lib/render_sync/clients/pusher.rb', line 44

def data
  @data
end

Class Method Details

.batch_publish(messages) ⇒ Object



46
47
48
49
50
# File 'lib/render_sync/clients/pusher.rb', line 46

def self.batch_publish(messages)
  messages.each do |message|
    message.publish
  end
end

Instance Method Details

#publishObject



57
58
59
60
61
62
63
# File 'lib/render_sync/clients/pusher.rb', line 57

def publish
  if RenderSync.async?
    publish_asynchronous
  else
    publish_synchronous
  end
end

#publish_asynchronousObject



69
70
71
72
73
# File 'lib/render_sync/clients/pusher.rb', line 69

def publish_asynchronous
  RenderSync.reactor.perform do
    ::Pusher.trigger_async([channel], 'sync', data)
  end
end

#publish_synchronousObject



65
66
67
# File 'lib/render_sync/clients/pusher.rb', line 65

def publish_synchronous
  ::Pusher.trigger([channel], 'sync', data)
end