class Configuration
Public Class Methods
new()
click to toggle source
do initializations
# File lib/configuration.rb, line 44 def initialize() # Use class-level logger for now. # init_logger() @log = @@log end
Public Instance Methods
method_missing(msg, *args)
click to toggle source
return any value stored in @config
# File lib/configuration.rb, line 76 def method_missing(msg, *args) ms = msg.to_sym # Exception-handling is not a control-structure. # This is. if @config[ms] return @config[ms] else return nil end end
set(options)
click to toggle source
Configure with the command-line arguments.
# File lib/configuration.rb, line 51 def set(options) @log.debug('options are: ' << options.to_s ) # User-provided configuration-file? if(options['config']) cf = options['config'] msg = check_file(cf, :file, :readable) if(!msg) @@config_file = cf else msg = trl("The file %s " << msg.split[1,100].join(' ')) %msg.split[0] @log.error(trl("ERROR! Unsuitable file") << ' ' << msg) give_up end end @log.debug('config-file is ' << @@config_file) # read defaults from configuration-file co = OpenStruct.new(YAML::load_file(@@config_file)) # merge and overwrite with the command-line arguments @config = co.to_h.merge(options.to_h) @log.debug('config is now: ' << @config.to_s ) verify end
Private Instance Methods
give_up()
click to toggle source
exit on error
# File lib/configuration.rb, line 90 def give_up @log.error("\t" << trl("Aborting. Bye!")) exit false end
verify()
click to toggle source
Do a maximum of verifications. Not everything is possible before the database has been read.
# File lib/configuration.rb, line 97 def verify msg = nil # ensure :source is set if(! @config[:source] ) msg = trl('missing argument %s') %'source' # either :name or :list are needed in addition elsif (!@config[:name] && !@config[:list]) msg = trl("Either --name (-n) or --list (-l) is needed as additional program-argument" ) end # avoid contradicting options if !msg && @config[:target] && @config[:out] msg = trl("contradictory arguments (%s):" %['target', 'out']) end if msg @log.error msg @log.error(trl("Start this program with parameter -h or --help to see the usage-message.") ) give_up end end