]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - lib/rbot/rbotconfig.rb
Changes that will (hopefully) make rbot work directly from the SVN checkout
[user/henk/code/ruby/rbot.git] / lib / rbot / rbotconfig.rb
1 module Irc
2   module Config
3     @@datadir = nil
4
5     # first try for the default path to the data dir    
6     defaultdir = File.expand_path(File.dirname($0) + '/../data')
7
8     if File.directory? "#{defaultdir}/rbot"
9       @@datadir = "#{defaultdir}/rbot"
10     end
11     
12     # setup pkg-based configuration - i.e. where were we installed to, where
13     # are our data files, etc.
14     if @@datadir.nil?
15       begin
16         debug "trying to load rubygems"
17         require 'rubygems'
18         debug "loaded rubygems, looking for rbot-#$version"
19         gemname, gem = Gem.source_index.find{|name, spec| spec.name == 'rbot' && spec.version.version == $version}
20         debug "got gem #{gem}"
21         if gem && path = gem.full_gem_path
22           debug "installed via rubygems to #{path}"
23           @@datadir = "#{path}/data/rbot"
24         else
25           debug "not installed via rubygems"
26         end
27       rescue LoadError,NameError,NoMethodError
28         debug "no rubygems installed"
29       end
30     end
31
32     if @@datadir.nil?
33       begin
34         require 'rbot/pkgconfig'
35         @@datadir = PKGConfig::DATADIR
36       rescue LoadError
37         puts "fatal - no way to determine data dir"
38         exit 2
39       end
40     end
41     
42     def Config.datadir
43       @@datadir
44     end
45   end
46 end