class ActionCableClient::MessageFactory

Attributes

channel[R]
identifier[R]

Public Class Methods

new(channel) click to toggle source

@param [String or Hash] channel - the name of the subscribed channel, or

a hash that includes the :channel key and any other params to send.
# File lib/action_cable_client/message_factory.rb, line 9
def initialize(channel)
  # the ending result should look like
  # "{"channel":"RoomChannel"}" but that's up to
  # the Mesage to format it
  @channel = channel
  @identifier =
    case channel
    when String then { channel: channel }
    when Hash then channel
    else
      raise ActionCableClient::Errors::ChannelNotSpecified, 'channel is invalid'
    end
end

Public Instance Methods

build_data(action, message) click to toggle source

@param [String] action - the action that is performed to send this message @param [Hash] message - the data to send @return [Hash] The data that will be included in the message

# File lib/action_cable_client/message_factory.rb, line 34
def build_data(action, message)
  message.merge(action: action) if message.is_a?(Hash)
end
create(command, action = '', message = nil) click to toggle source

@param [String] command - the type of message that this is @param [String] action - the action that is performed to send this message @param [Hash] message - the data to send

# File lib/action_cable_client/message_factory.rb, line 26
def create(command, action = '', message = nil)
  data = build_data(action, message)
  Message.new(command, identifier, data)
end