# Module: Tgconfig

# Tgconfig (Configuration)

Tgconfig handles configuration file management Configuration is stored in YAML syntax formatting.

# Constants

Name | Value
--- | ---
Configfile | "./conf/opentg.conf.yaml"

# Public Class Methods

### load ()

Load in the YAML configuration file and returns

Show source...

         # File bbs/lib/tgconfig.rb, line 105
    105:   def Tgconfig.load
    106:     cfg = File.open(Configfile)  { |yf| YAML::load( yf ) }
    107:     # => Ensure loaded data is a hash. ie: YAML load was OK
    108:     if cfg.class != Hash
    109:        raise "ERROR: Tgconfig - invalid format or parsing error."
    110:     # => If all is well, perform deeper validation
    111:     else
    112:       # => PARSE & CHECK: Database Section
    113:       if cfg['database'].nil?
    114:         raise "ERROR: Tgconfig - database section not defined."
    115:       else
    116:         case cfg['database']['type']
    117:           when "embedded"
    118:           when "remote"
    119:             raise "ERROR: Tgconfig - database driver field missing." if cfg['database']['driver'].nil?
    120:             raise "ERROR: Tgconfig - database host field missing." if cfg['database']['host'].nil?
    121:             raise "ERROR: Tgconfig - database name field missing." if cfg['database']['name'].nil?
    122:             raise "ERROR: Tgconfig - database user field missing." if cfg['database']['user'].nil?
    123:             raise "ERROR: Tgconfig - database pass field missing." if cfg['database']['pass'].nil?
    124:           else
    125:             raise "ERROR: Tgconfig - datbase configuration type is invalid."
    126:         end #-> /case
    127:       end #-> /Parse DB
    128:
    129:       # => PARSE & CHECK: BBS Section
    130:       if cfg['bbs'].nil?
    131:         raise "ERROR: Tgconfig - bbs section not defined."
    132:       else
    133:         raise "ERROR: Tgconfig - bbs name field missing." if cfg['bbs']['name'].nil?
    134:         raise "ERROR: Tgconfig - bbs tagline field missing." if cfg['bbs']['tagline'].nil?
    135:       end #-> /Parse BBS
    136:     end #-> /if !Hash
    137:
    138:     # => If all is well, return the configuration
    139:     return cfg
    140:   end

### makedefault (filename)

Builds a default YAML configuration and outputs the filename specified.

Show source...

         # File bbs/lib/tgconfig.rb, line 62
     62:   def Tgconfig.makedefault(filename)
     63:     cfghash = {
     64:             "database" => {
     65:                     "type"    => "embedded",
     66:                     "driver"  => "jdbc:postgresql",
     67:                     "host"    => "localhost:5432",
     68:                     "name"    => "database",
     69:                     "user"    => "username",
     70:                     "pass"    => "pass"
     71:             },
     72:             "bbs" => {
     73:                     "name"    => "Telegard/2 BBS",
     74:                     "tagline" => "Another Installation of OpenTelegard/2",
     75:                     "theme"   => "opentg"
     76:             },
     77:             "login" => {
     78:                     "attempts"=> 5,
     79:                     "lockout" => 8,
     80:                     "usehint" => true,
     81:                     "allownew" => true
     82:
     83:             },
     84:             "signup" => {
     85:                     "ask_address" => true,
     86:                     "ask_postal" => true,
     87:                     "ask_country" => true,
     88:                     "ask_phone" => true,
     89:                     "ask_gender" => true,
     90:                     "ask_bday" => true,
     91:                     "ask_custom1" => true,
     92:                     "custom1" => "How did you hear about us? (75 chars max)",
     93:                     "ask_custom2" => false,
     94:                     "custom2" => "",
     95:                     "ask_custom3" => false,
     96:                     "custom3" => ""
     97:             }
     98:     }
     99:     f = File.open(filename, "w")
    100:     f.puts YAML::dump(cfghash)
    101:     f.close
    102:   end