Class: Configuration

Inherits:
Object
  • Object
show all
Includes:
BasicLogging, Singleton
Defined in:
lib/configuration.rb

Overview

An object of this class represents the configuration of the program. The parameters are set in the configuration-file

Constant Summary

Constants included from BasicLogging

BasicLogging::DEBUG, BasicLogging::ERROR, BasicLogging::FATAL, BasicLogging::INFO, BasicLogging::Levels, BasicLogging::UNKNOWN, BasicLogging::WARN

Instance Attribute Summary collapse

Attributes included from BasicLogging

#target

Instance Method Summary collapse

Methods included from BasicLogging

is_muted?, #log, mute, #set_level, #set_target

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/configuration.rb', line 27

def initialize() 
  confname = PROGNAME << '.conf' 
  # try to open user-configuration
  @config_file = ENV['HOME'].dup << File::Separator << '.' << confname
  # if user-configuration does not exist, copy installed version.
  if !File.exist?(@config_file)
    begin
      File.open(@config_file, 'w') do |cf|
        cf.write(File.read( File::dirname(File::absolute_path(__FILE__)) << File::Separator << confname) )
      end
    rescue => ex
      STDERR.puts('Cannot write user-configuration to ' << @config_file << '! (' << ex.message << ')' )
    end
  end
  # read the config-file.
  read_config
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, args = nil) ⇒ Object

What this object does not have, may still be in the configuration.



46
47
48
49
50
# File 'lib/configuration.rb', line 46

def method_missing(method, args = nil)
  v = @conf[method]
  debug('method_missing returns value for ' << method.to_s << ': |' << v.to_s << '|') 
  return v
end

Instance Attribute Details

#log_levelObject (readonly)

Returns the value of attribute log_level.



60
61
62
# File 'lib/configuration.rb', line 60

def log_level
  @log_level
end

#log_targetObject (readonly)

Returns the value of attribute log_target.



60
61
62
# File 'lib/configuration.rb', line 60

def log_target
  @log_target
end

Instance Method Details

#set(key, value) ⇒ Object

set a configuration option.



53
54
55
56
57
58
# File 'lib/configuration.rb', line 53

def set(key, value)
  @conf[key] = value
  if key == 'DEBUG_LOG' 
    set_target value
  end
end