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'
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



16
17
18
19
20
# File 'lib/action_cable_client/message.rb', line 16

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

Instance Attribute Details

#_commandObject (readonly)

Returns the value of attribute _command.



11
12
13
# File 'lib/action_cable_client/message.rb', line 11

def _command
  @_command
end

#_dataObject (readonly)

Returns the value of attribute _data.



11
12
13
# File 'lib/action_cable_client/message.rb', line 11

def _data
  @_data
end

#_identifierObject (readonly)

Returns the value of attribute _identifier.



11
12
13
# File 'lib/action_cable_client/message.rb', line 11

def _identifier
  @_identifier
end

Instance Method Details

#to_jsonObject



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

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

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

  hash.to_json
end