Class: ActionChannels::Channel
- Inherits:
-
Object
- Object
- ActionChannels::Channel
- Defined in:
- lib/action_channels/channel.rb
Instance Attribute Summary collapse
-
#clients ⇒ Object
readonly
Returns the value of attribute clients.
-
#message_sender ⇒ Object
Returns the value of attribute message_sender.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #add_client(client) ⇒ Object
-
#initialize(attrs) ⇒ Channel
constructor
A new instance of Channel.
- #notify_all(message) ⇒ Object
- #process_message(message) ⇒ Object
- #remove_client(client) ⇒ Object
- #send_message(receiver, message) ⇒ Object
Constructor Details
#initialize(attrs) ⇒ Channel
Returns a new instance of Channel.
14 15 16 17 18 |
# File 'lib/action_channels/channel.rb', line 14 def initialize(attrs) @name = attrs.fetch(:name) @clients = Set.new @message_sender = attrs.fetch :message_sender, MessageSenders::WebSocket.new end |
Instance Attribute Details
#clients ⇒ Object (readonly)
Returns the value of attribute clients.
11 12 13 |
# File 'lib/action_channels/channel.rb', line 11 def clients @clients end |
#message_sender ⇒ Object
Returns the value of attribute message_sender.
12 13 14 |
# File 'lib/action_channels/channel.rb', line 12 def @message_sender end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/action_channels/channel.rb', line 11 def name @name end |
Class Method Details
.input_message_types ⇒ Object
3 4 5 |
# File 'lib/action_channels/channel.rb', line 3 def self. %w(subscribe unsubscribe publish) end |
.output_message_types ⇒ Object
7 8 9 |
# File 'lib/action_channels/channel.rb', line 7 def self. %w(subscribed unsubscribed published news invalid_message) end |
Instance Method Details
#add_client(client) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/action_channels/channel.rb', line 24 def add_client(client) clients << client ActionChannels.logger.info "The channel ##{self.name} added a client" ActionChannels.logger.debug "Count of client of channel ##{self.name} is #{self.clients.count}." end |
#notify_all(message) ⇒ Object
38 39 40 41 42 |
# File 'lib/action_channels/channel.rb', line 38 def notify_all() clients.each do |client| client, end end |
#process_message(message) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/action_channels/channel.rb', line 44 def () ActionChannels.logger.debug "The channel ##{self.name} received a message #{.inspect}" case .type when 'subscribe' on_subscribe ., .details when 'unsubscribe' on_unsubscribe ., .details when 'publish' on_publish ., .details else ., .type end end |
#remove_client(client) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/action_channels/channel.rb', line 31 def remove_client(client) clients.delete client ActionChannels.logger.info "The channel ##{self.name} removed a client" ActionChannels.logger.debug "Count of client of channel ##{self.name} is #{self.clients.count}." end |
#send_message(receiver, message) ⇒ Object
20 21 22 |
# File 'lib/action_channels/channel.rb', line 20 def (receiver, ) .do_send(receiver, ) end |