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'- 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.
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
#_command ⇒ Object (readonly)
Returns the value of attribute _command.
11 12 13 |
# File 'lib/action_cable_client/message.rb', line 11 def _command @_command end |
#_data ⇒ Object (readonly)
Returns the value of attribute _data.
11 12 13 |
# File 'lib/action_cable_client/message.rb', line 11 def _data @_data end |
#_identifier ⇒ Object (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_json ⇒ Object
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 |