Class: ActionCableClient::MessageFactory
- Inherits:
-
Object
- Object
- ActionCableClient::MessageFactory
- Defined in:
- lib/action_cable_client/message_factory.rb
Instance Attribute Summary collapse
-
#_channel ⇒ Object
readonly
Returns the value of attribute _channel.
Instance Method Summary collapse
-
#build_data(action, message) ⇒ Hash
The data that will be included in the message.
- #create(command, action = '', message = nil) ⇒ Object
-
#identifier ⇒ Object
the ending result should look like “”channel“:”RoomChannel“” but that’s up to the Mesage to format it.
-
#initialize(channel) ⇒ MessageFactory
constructor
A new instance of MessageFactory.
Constructor Details
#initialize(channel) ⇒ MessageFactory
Returns a new instance of MessageFactory.
7 8 9 |
# File 'lib/action_cable_client/message_factory.rb', line 7 def initialize(channel) @_channel = channel end |
Instance Attribute Details
#_channel ⇒ Object (readonly)
Returns the value of attribute _channel.
4 5 6 |
# File 'lib/action_cable_client/message_factory.rb', line 4 def _channel @_channel end |
Instance Method Details
#build_data(action, message) ⇒ Hash
Returns The data that will be included in the message.
22 23 24 |
# File 'lib/action_cable_client/message_factory.rb', line 22 def build_data(action, ) .merge(action: action) if .is_a?(Hash) end |
#create(command, action = '', message = nil) ⇒ Object
14 15 16 17 |
# File 'lib/action_cable_client/message_factory.rb', line 14 def create(command, action = '', = nil) data = build_data(action, ) Message.new(command, identifier, data) end |
#identifier ⇒ Object
the ending result should look like “”channel“:”RoomChannel“” but that’s up to the Mesage to format it
29 30 31 |
# File 'lib/action_cable_client/message_factory.rb', line 29 def identifier { channel: _channel } end |