class Garufa::Message
Constants
- ACTIVITY_TIMEOUT
- ATTRIBUTES
Public Class Methods
channel_event(channel, event, data)
click to toggle source
# File lib/garufa/message.rb, line 25 def self.channel_event(channel, event, data) new(channel: channel, event: event, data: data) end
connection_established(socket_id)
click to toggle source
# File lib/garufa/message.rb, line 29 def self.connection_established(socket_id) data = { socket_id: socket_id, activity_timeout: ACTIVITY_TIMEOUT }.to_json new(event: 'pusher:connection_established', data: data) end
error(code, message)
click to toggle source
# File lib/garufa/message.rb, line 42 def self.error(code, message) data = { code: code, message: message }.to_json new(event: 'pusher:error', data: data) end
new(attributes)
click to toggle source
# File lib/garufa/message.rb, line 10 def initialize(attributes) @attributes = ATTRIBUTES.each_with_object({}) do |key, hash| hash[key] = attributes[key] || attributes[key.to_s] end @attributes.each do |name, value| instance_variable_set("@#{name}", value) define_singleton_method(name.to_sym) { value } end end
pong()
click to toggle source
# File lib/garufa/message.rb, line 38 def self.pong new(event: 'pusher:pong', data: {}) end
subscription_succeeded(channel, data = {})
click to toggle source
# File lib/garufa/message.rb, line 34 def self.subscription_succeeded(channel, data = {}) new(event: 'pusher_internal:subscription_succeeded', channel: channel, data: data) end
Public Instance Methods
to_json()
click to toggle source
# File lib/garufa/message.rb, line 21 def to_json @attributes.delete_if { |k, v| v.nil? }.to_json end