Class: Configuration

Inherits:
Object
  • Object
show all
Includes:
Logging, 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 and – for a single article – … in the PPParam header (unused)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#init_logger, #log_level=, #log_target=

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/configuration.rb', line 37

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
  # initialize the object-level logger according to configuration.
  @log = init_logger(log_target, log_level)
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.



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

def method_missing(method, args = nil)
  @log.debug('deliver conf value ' << method.to_s)
  @conf[method]
end

Instance Attribute Details

#log_levelObject (readonly)

Returns the value of attribute log_level.



68
69
70
# File 'lib/configuration.rb', line 68

def log_level
  @log_level
end

#log_targetObject (readonly)

Returns the value of attribute log_target.



68
69
70
# File 'lib/configuration.rb', line 68

def log_target
  @log_target
end

Instance Method Details

#set(key, value) ⇒ Object

set a configuration option.



64
65
66
# File 'lib/configuration.rb', line 64

def set(key, value)
  @conf[key] = value
end