C0 code coverage information
Generated on Sun Jul 06 22:30:58 +0900 2008 with rcov 0.8.1.2
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
1 #!/usr/bin/env ruby
2
3 require "net/irc"
4 require "ostruct"
5 require "logger"
6 require "yaml"
7 require "monitor"
8
9 module Citrus
10 class Core < Net::IRC::Client
11
12 attr_reader :socket, :plugins, :config
13
14 def initialize(config)
15 if config.is_a? Hash
16 @config = OpenStruct.new({
17 "general" => {},
18 "plugins" => {},
19 }.merge(config))
20 init_config
21 else
22 @config_file = config.to_s
23 reload_config
24 end
25
26 @logger = Logger.new(@config.general["log"] || $stdout)
27 @logger.level = eval("Logger::#{@config.general['log_level'].upcase}") if @config.general['log_level']
28 @logger.progname = File.basename($0)
29
30 %w(host port nick user real).each do |req|
31 raise ArgumentError, "config general/#{req} is required." if @config.general[req].nil?
32 end
33
34 super(@config.general["host"], @config.general["port"], {
35 :nick => @config.general["nick"],
36 :user => @config.general["user"],
37 :real => @config.general["real"],
38 :pass => @config.general["pass"],
39 :logger => @logger,
40 })
41
42 @plugins = Plugins.new(@config.general["plugin_dir"])
43 end
44
45 def reload_config
46 raise "Passed not filename but Hash to new." unless @config_file
47 @config = OpenStruct.new(File.open(@config_file) {|f| YAML.load(f) })
48 init_config
49 end
50
51 def init_config
52 @config.general["plugin_dir"] ||= "plugins"
53 @config.general["data_dir"] ||= "data"
54 end
55
56 def init_plugins
57 @plugins.update
58 @config.plugins.each do |name, _|
59 begin
60 unless @plugins.loaded_plugins.key?(name)
61 @plugins.load(name, self, @config.plugins)
62 end
63 rescue Plugins::UnknownPlugin => e
64 @logger.error "#{e.message}"
65 end
66 end
67 end
68
69 def load_plugin(name)
70 config = @config.plugins
71 @plugins.load(name, self, config || {})
72 end
73
74 def reload_plugin(name)
75 config = @config.plugins
76 @plugins.reload(name, self, config || {})
77 end
78
79 def reload_plugins
80 reload_plugin(:all)
81 end
82
83 def unload_plugin(name)
84 @plugins.unload(name)
85 end
86
87 def on_connected
88 super
89 init_plugins
90 call_plugins :on_uped, []
91 end
92
93 def on_disconnected
94 super
95 call_plugins :on_downed, []
96 end
97
98 def on_privmsg(m)
99 super
100 target = m[0]
101 mes = m[1]
102
103 case
104 when m.ctcp?
105 call_plugins :on_ctcp, [m.prefix, target, ctcp_decoding(mes)]
106 when ![?#, ?+, ?&, ?!].include?(target[0])
107 call_plugins :on_talk, [m.prefix, target, mes]
108 else
109 call_plugins :on_privmsg, [m.prefix, target, mes]
110 end
111 end
112
113 def on_notice(m)
114 super
115 call_plugins :on_notice, [m.prefix, m[0], m[1]]
116 end
117
118 def on_join(m)
119 super
120 call_plugins :on_join, [m.prefix, m[0]]
121 end
122
123 def on_part(m)
124 super
125 call_plugins :on_part, [m.prefix, m[0], m[1]]
126 end
127
128 def on_kick(m)
129 super
130 call_plugins :on_kick, [m.prefix, m[0].split(/,/), m[1].split(/,/), m[2]]
131 end
132
133 def on_invite(m)
134 super
135 call_plugins :on_invite, [m.prefix, m[0], m[1]]
136 end
137
138 def on_nick(m)
139 super
140 call_plugins :on_nick, [m.prefix, m[0]]
141 end
142
143 def on_mode(m)
144 negative_mode, positive_mode, = *super
145 call_plugins :on_mode, [m.prefix, m[0], positive_mode, negative_mode]
146 end
147
148 def on_message(m)
149 call_plugins :on_message, [m]
150 nil
151 end
152
153 def call_plugins(name, args)
154 @plugins.each do |n, i|
155 if args[1] && [?#, ?+, ?&, ?!].include?(args[1][0]) # when channel
156 channel = args[1]
157 config = @config.plugins[n] || {}
158 enabled = config["enabled"]
159 disabled = config["disabled"]
160
161 case
162 when enabled
163 next unless enabled.find {|c| c === channel }
164 when disabled
165 next if disabled.find {|c| c === channel }
166 end
167 end
168 Thread.start(n, i) do |nm, ins|
169 begin
170 ins.send(name, *args)
171 rescue Exception => e
172 log "#{nm} #{e.message}"
173 e.backtrace.each do |l|
174 @logger.error "#{nm} \t#{l}"
175 end
176 if @config.general["error"]
177 post NOTICE, @config.general["error"], "Error: #{e.inspect}"
178 end
179 end
180 end
181 end
182 end
183
184 def log(l)
185 @logger.info(l)
186 end
187 end
188 end
189
Generated using the rcov code coverage analysis tool for Ruby
version 0.8.1.2.