Class: Codebot::IRCClient
- Inherits:
-
Object
- Object
- Codebot::IRCClient
- Defined in:
- lib/codebot/irc_client.rb
Overview
This class manages an IRC client.
Instance Method Summary collapse
-
#dispatch(request) ⇒ Object
Dispatches a new request.
-
#initialize(core) ⇒ IRCClient
constructor
Creates a new IRC client.
-
#join ⇒ Object
Waits for active connections to finish.
-
#migrate! ⇒ Object
Connects to and disconnects from networks as necessary in order for the list of connections to reflect changes to the configuration.
-
#start ⇒ Object
Starts the IRC client.
-
#stop ⇒ Object
Stops the IRC client.
Constructor Details
#initialize(core) ⇒ IRCClient
Creates a new IRC client.
11 12 13 14 15 16 17 |
# File 'lib/codebot/irc_client.rb', line 11 def initialize(core) @active = false @checkpoint = [] @connections = [] @core = core @semaphore = Mutex.new end |
Instance Method Details
#dispatch(request) ⇒ Object
Dispatches a new request.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/codebot/irc_client.rb', line 22 def dispatch(request) request.each_network do |network, channels| connection = connection_to(network) next if connection.nil? channels.each do |channel| = request. channel connection.enqueue end end end |
#join ⇒ Object
Waits for active connections to finish.
50 51 52 |
# File 'lib/codebot/irc_client.rb', line 50 def join @connections.each(&:join) end |
#migrate! ⇒ Object
Connects to and disconnects from networks as necessary in order for the list of connections to reflect changes to the configuration.
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/codebot/irc_client.rb', line 56 def migrate! @semaphore.synchronize do return unless @active networks = @core.config.networks (@checkpoint - networks).each { |network| disconnect_from network } (networks - @checkpoint).each { |network| connect_to network } @checkpoint = networks end end |
#start ⇒ Object
Starts the IRC client.
35 36 37 38 |
# File 'lib/codebot/irc_client.rb', line 35 def start @active = true migrate! end |
#stop ⇒ Object
Stops the IRC client.
41 42 43 44 45 46 47 |
# File 'lib/codebot/irc_client.rb', line 41 def stop @active = false @checkpoint.clear @connections.each(&:stop) join @connections.clear end |