Class: Blur::Client
- Inherits:
-
Object
- Object
- Blur::Client
- Includes:
- Handling, Logging
- Defined in:
- library/blur/client.rb,
library/blur/handling.rb
Overview
The Client class is the controller of the low-level access.
It stores networks, scripts and callbacks, and is also encharge of distributing the incoming commands to the right networks and scripts.
Defined Under Namespace
Modules: Handling
Instance Attribute Summary (collapse)
-
- (Array) networks
A list of instantiated networks.
-
- (Array) options
The options that is passed upon initialization.
-
- (Array) scripts
A list of scripts that is loaded during runtime.
Instance Method Summary (collapse)
-
- (Object) connect
Connect to each network available that is not already connected, then proceed to start the run-loop.
-
- (Object) got_command(network, command)
Is called when a command have been received and parsed, this distributes the command to the loader, which then further distributes it to events and scripts.
-
- (Client) initialize(options)
constructor
Instantiates the client, stores the options, instantiates the networks and then loads available scripts.
-
- (Object) load_scripts
Searches for scripts in working_directory/scripts and then loads them.
-
- (Object) quit(signal = :SIGINT)
Try to gracefully disconnect from each network, unload all scripts and exit properly.
-
- (Object) unload_scripts
Unload all scripts gracefully that have been loaded into the client.
Methods included from Handling
#got_channel_topic, #got_end_of_motd, #got_join, #got_kick, #got_mode, #got_name_reply, #got_nick, #got_part, #got_ping, #got_privmsg, #got_quit, #got_topic
Constructor Details
- (Client) initialize(options)
Instantiates the client, stores the options, instantiates the networks and then loads available scripts.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'library/blur/client.rb', line 26 def initialize @options = @scripts = [] @networks = [] @callbacks = {} @networks = @options[:networks].map {|| Network.new } load_scripts trap 2, &method(:quit) end |
Instance Attribute Details
- (Array) networks
A list of instantiated networks.
18 19 20 |
# File 'library/blur/client.rb', line 18 def networks @networks end |
- (Array) options
The options that is passed upon initialization.
14 15 16 |
# File 'library/blur/client.rb', line 14 def @options end |
- (Array) scripts
A list of scripts that is loaded during runtime.
16 17 18 |
# File 'library/blur/client.rb', line 16 def scripts @scripts end |
Instance Method Details
- (Object) connect
Connect to each network available that is not already connected, then proceed to start the run-loop.
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'library/blur/client.rb', line 40 def connect networks = @networks.select {|network| not network.connected? } EventMachine.run do networks.each do |network| network.delegate = self network.connect end EventMachine.error_handler{|e| p e } end end |
- (Object) got_command(network, command)
Is called when a command have been received and parsed, this distributes the command to the loader, which then further distributes it to events and scripts.
59 60 61 62 63 64 65 66 |
# File 'library/blur/client.rb', line 59 def got_command network, command log "#{'←' ^ :green} #{command.name.to_s.ljust(8, ' ') ^ :light_gray} #{command.params.map(&:inspect).join ' '}" name = :got_#{command.name.downcase}" if respond_to? name __send__ name, network, command end end |
- (Object) load_scripts
Searches for scripts in working_directory/scripts and then loads them.
69 70 71 72 73 74 75 76 77 78 |
# File 'library/blur/client.rb', line 69 def load_scripts script_path = File.dirname $0 Dir.glob("#{script_path}/scripts/*.rb").each do |path| script = Script.new path script.__client = self @scripts << script end end |
- (Object) quit(signal = :SIGINT)
Try to gracefully disconnect from each network, unload all scripts and exit properly.
93 94 95 96 97 98 99 100 101 102 |
# File 'library/blur/client.rb', line 93 def quit signal = :SIGINT @networks.each do |network| network.transmit :QUIT, "Got SIGINT?" network.disconnect end unload_scripts EventMachine.stop end |
- (Object) unload_scripts
Unload all scripts gracefully that have been loaded into the client.
83 84 85 86 87 |
# File 'library/blur/client.rb', line 83 def unload_scripts @scripts.each do |script| script.unload! end.clear end |