summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2013-05-12 23:36:52 -0700
committerelijah <elijah@riseup.net>2013-05-12 23:36:52 -0700
commit0c74967d5db0d6af89212f3c4a35c38290cf2975 (patch)
tree0dfaa38572c7ca44bf9a1f5d60e0e97c963238f7 /lib
parent166a59c7dff659f2ebf93c56c4e8d0567ec65404 (diff)
added config file
Diffstat (limited to 'lib')
-rw-r--r--lib/nickserver/config.rb47
1 files changed, 41 insertions, 6 deletions
diff --git a/lib/nickserver/config.rb b/lib/nickserver/config.rb
index d47fc68..56478e2 100644
--- a/lib/nickserver/config.rb
+++ b/lib/nickserver/config.rb
@@ -1,14 +1,49 @@
+require 'yaml'
+
module Nickserver
class Config
+ PATHS = [
+ File.expand_path('../../../config/default.yml', __FILE__),
+ '/etc/leap/nickserver.yml'
+ ]
+
class << self
attr_accessor :sks_url
+ attr_accessor :couch_port
+ attr_accessor :couch_host
+ attr_accessor :couch_database
attr_accessor :port
+ attr_accessor :loaded
end
- end
- #
- # set reasonable defaults
- #
- Config.sks_url = 'https://hkps.pool.sks-keyservers.net:/pks/lookup'
- Config.port = 6425 # aka "NICK"
+ def self.load
+ self.loaded ||= begin
+ PATHS.each do |file_path|
+ self.load_config(file_path)
+ end
+ true
+ end
+ end
+
+ private
+
+ def self.load_config(file_path)
+ begin
+ YAML.load(File.read(file_path)).each do |key, value|
+ begin
+ self.send("#{key}=", value)
+ rescue NoMethodError => exc
+ STDERR.puts "ERROR in file #{file_path}, '#{key}' is not a valid option"
+ exit(1)
+ end
+ end
+ puts "Loaded #{file_path}"
+ rescue Errno::ENOENT => exc
+ puts "Skipping #{file_path}"
+ rescue Exception => exc
+ STDERR.puts exc.inspect
+ exit(1)
+ end
+ end
+ end
end