# config.rb - configuration manager # # Copyright (C) 2002 Yoshinori K. Okuji # # This file is part of BugCommunicator. # # BugCommunicator is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # BugCommunicator is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with BugCommunicator; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA module BugCommunicator class Config def initialize(file) m = Module.new m.module_eval(IO.readlines(file, nil).first, file) # Set the defaults. @host = 'localhost' @port = 8844 @acl = nil @size_limit = nil @address = nil @smtp_host = 'localhost' @admin_address = nil @url = nil @db_host = 'localhost' @db_name = 'bugcomm' @db_user = 'bugcomm' @db_password = nil @template_dir = nil if defined?(m::HOST) unless m::HOST.kind_of?(String) raise TypeError, 'HOST must be a string' end @host = m::HOST end if defined?(m::PORT) unless m::PORT.kind_of?(Integer) raise TypeError, 'PORT must be a string' end @port = m::PORT end if defined?(m::ACL) unless m::ACL.kind_of?(Array) raise TypeError, 'ACL must be an array' end @acl = m::ACL end if defined?(m::SIZE_LIMIT) unless m::SIZE_LIMIT.kind_of?(Integer) raise TypeError, 'SIZE_LIMIT must be an integer' end @size_limit = m::SIZE_LIMIT end if defined?(m::ADDRESS) unless m::ADDRESS.kind_of?(String) raise TypeError, 'ADDRESS must be an string' end @address = m::ADDRESS else raise RuntimeError, 'ADDRESS must be defined' end if defined?(m::SMTP_HOST) unless m::SMTP_HOST.kind_of?(String) raise TypeError, 'SMTP_HOST must be an string' end @smtp_host = m::SMTP_HOST end if defined?(m::ADMIN_ADDRESS) unless m::ADMIN_ADDRESS.kind_of?(String) raise TypeError, 'ADMIN_ADDRESS must be an string' end @admin_address = m::ADMIN_ADDRESS else raise RuntimeError, 'ADMIN_ADDRESS must be defined' end if defined?(m::URL) unless m::URL.kind_of?(String) raise TypeError, 'URL must be a string' end @url = m::URL else raise RuntimeError, 'URL must be defined' end if defined?(m::DB_HOST) unless m::DB_HOST.kind_of?(String) raise TypeError, 'DB_HOST must be an string' end @db_host = m::DB_HOST end if defined?(m::DB_NAME) unless m::DB_NAME.kind_of?(String) raise TypeError, 'DB_NAME must be an string' end @db_name = m::DB_NAME end if defined?(m::DB_USER) unless m::DB_USER.kind_of?(String) raise TypeError, 'DB_USER must be an string' end @db_user = m::DB_USER end if defined?(m::DB_PASSWORD) unless m::DB_PASSWORD.kind_of?(String) raise TypeError, 'DB_PASSWORD must be an string' end @db_password = m::DB_PASSWORD end end attr_reader :host, :port, :acl, :size_limit attr_reader :address, :smtp_host, :admin_address attr_reader :url attr_reader :db_host, :db_name, :db_user attr_accessor :db_password, :template_dir end end