Class: ActionCableClient::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/action_cable_client/message.rb

Constant Summary collapse

IDENTIFIER_KEY =
'identifier'
IDENTIFIER_PING =
'ping'
IDENTIFIER_WELCOME =
'welcome'
TYPE_KEY =

Type is never sent, but is received TODO: find a better place for this constant

'type'
TYPE_CONFIRM_SUBSCRIPTION =
'confirm_subscription'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, identifier, data) ⇒ Message

Returns a new instance of Message.

Parameters:

  • command (String)
    • the type of message that this is

  • identifier (Hash)
    • the channel we are subscribed to

  • data (Hash)
    • the data to be sent in this message



18
19
20
21
22
# File 'lib/action_cable_client/message.rb', line 18

def initialize(command, identifier, data)
  @_command = command
  @_identifier = identifier
  @_data = data
end

Instance Attribute Details

#_commandObject (readonly)

Returns the value of attribute _command.



13
14
15
# File 'lib/action_cable_client/message.rb', line 13

def _command
  @_command
end

#_dataObject (readonly)

Returns the value of attribute _data.



13
14
15
# File 'lib/action_cable_client/message.rb', line 13

def _data
  @_data
end

#_identifierObject (readonly)

Returns the value of attribute _identifier.



13
14
15
# File 'lib/action_cable_client/message.rb', line 13

def _identifier
  @_identifier
end

Instance Method Details

#to_jsonObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/action_cable_client/message.rb', line 24

def to_json
  hash = {
    command: _command,
    identifier: _identifier.to_json
  }

  hash[:data] = _data.to_json if present?(_data)

  hash.to_json
end