class ActionCableClient::Message
Constants
- IDENTIFIER_KEY
- IDENTIFIER_PING
- IDENTIFIER_WELCOME
- TYPE_CONFIRM_SUBSCRIPTION
- TYPE_KEY
Type is never sent, but is received TODO: find a better place for this constant
Attributes
_command[R]
_data[R]
_identifier[R]
Public Class Methods
new(command, identifier, data)
click to toggle source
@param [String] command - the type of message that this is @param [Hash] identifier - the channel we are subscribed to @param [Hash] data - the data to be sent in this message
# File lib/action_cable_client/message.rb, line 18 def initialize(command, identifier, data) @_command = command @_identifier = identifier @_data = data end
Public Instance Methods
to_json()
click to toggle source
# 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
Private Instance Methods
present?(data)
click to toggle source
# File lib/action_cable_client/message.rb, line 37 def present?(data) case data when String !(data.empty? || /\A[[:space:]]*\z/.match(data)) else data.respond_to?(:empty?) ? !data.empty? : !!data end end