Class: ActionCableClient::Message
- Inherits:
-
Object
- Object
- ActionCableClient::Message
- 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
-
#_command ⇒ Object
readonly
Returns the value of attribute _command.
-
#_data ⇒ Object
readonly
Returns the value of attribute _data.
-
#_identifier ⇒ Object
readonly
Returns the value of attribute _identifier.
Instance Method Summary collapse
-
#initialize(command, identifier, data) ⇒ Message
constructor
A new instance of Message.
- #to_json ⇒ Object
Constructor Details
#initialize(command, identifier, data) ⇒ Message
Returns a new instance of 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
#_command ⇒ Object (readonly)
Returns the value of attribute _command.
13 14 15 |
# File 'lib/action_cable_client/message.rb', line 13 def _command @_command end |
#_data ⇒ Object (readonly)
Returns the value of attribute _data.
13 14 15 |
# File 'lib/action_cable_client/message.rb', line 13 def _data @_data end |
#_identifier ⇒ Object (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_json ⇒ Object
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 |