Class: Configuration

Inherits:
Object
  • Object
show all
Includes:
File_Checking, Logging, Translating
Defined in:
lib/configuration.rb

Constant Summary collapse

@@config_file =

default configuration file

File::dirname(__FILE__) << File::Separator << 'config'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#debout, #formatter, #init_logger, #log_level=, #log_level?, #log_target=

Methods included from Translating

language, trl, #trl

Methods included from File_Checking

file_check, #file_check, file_type

Constructor Details

#initialize(options) ⇒ Configuration

do initializations



39
40
41
42
43
44
# File 'lib/configuration.rb', line 39

def initialize(options)
  init_logger(STDOUT)
  @log.level = $log_level
  set(options)
  @log.debug('config-file is ' << @@config_file)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(msg, *args) ⇒ Object

return any value stored in @config



67
68
69
70
71
72
73
74
75
76
# File 'lib/configuration.rb', line 67

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

Instance Attribute Details

#dictsObject (readonly)

Returns the value of attribute dicts.



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

def dicts
  @dicts
end

#fdelimObject (readonly)

Returns the value of attribute fdelim.



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

def fdelim
  @fdelim
end

#fieldsObject (readonly)

Returns the value of attribute fields.



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

def fields
  @fields
end

#placeholdersObject (readonly)

Returns the value of attribute placeholders.



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

def placeholders
  @placeholders
end

#templateObject (readonly)

Returns the value of attribute template.



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

def template
  @template
end

Instance Method Details

#user_confObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/configuration.rb', line 46

def user_conf
  confdir = ENV['HOME'].dup << File::Separator << '.config'
  Dir.mkdir(confdir) if !Dir.exist?(confdir)
  confdir = confdir << File::Separator << APPNAME
  Dir.mkdir(confdir) if !Dir.exist?(confdir)
  config = confdir << File::Separator << 'config'
  if(!File.exist?(config ) )
    begin
      File.open(config, 'w') {|co| co.write(File.read(@@config_file))}
      @log.info("Created user-version of the configuration-file in\n\t" << config)
    rescue Exception => ex
      @log.error('Cannot create the configuration: ' << ex.message)
      give_up
    end
  end
  return config
end