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.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
Instance Method Summary collapse
-
#build_data(action, message) ⇒ Hash
The data that will be included in the message.
- #create(command, action = '', message = nil) ⇒ Object
-
#initialize(channel) ⇒ MessageFactory
constructor
A new instance of MessageFactory.
Constructor Details
#initialize(channel) ⇒ MessageFactory
Returns a new instance of MessageFactory.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# 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 |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
5 6 7 |
# File 'lib/action_cable_client/message_factory.rb', line 5 def channel @channel end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
5 6 7 |
# File 'lib/action_cable_client/message_factory.rb', line 5 def identifier @identifier end |
Instance Method Details
#build_data(action, message) ⇒ Hash
Returns The data that will be included in the message.
34 35 36 |
# File 'lib/action_cable_client/message_factory.rb', line 34 def build_data(action, ) .merge(action: action) if .is_a?(Hash) end |
#create(command, action = '', message = nil) ⇒ Object
26 27 28 29 |
# File 'lib/action_cable_client/message_factory.rb', line 26 def create(command, action = '', = nil) data = build_data(action, ) Message.new(command, identifier, data) end |