Class: Configuration
- Inherits:
-
Object
- Object
- Configuration
- Includes:
- BasicLogging, Translating
- Defined in:
- lib/configuration.rb
Overview
TODO: write default configuration to file !
Constant Summary collapse
- @@config_file =
default configuration file
File::dirname(__FILE__) << File::Separator << 'config'
Instance Attribute Summary collapse
-
#dicts ⇒ Object
readonly
Returns the value of attribute dicts.
-
#fdelim ⇒ Object
readonly
Returns the value of attribute fdelim.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#placeholders ⇒ Object
readonly
Returns the value of attribute placeholders.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
-
#initialize(options) ⇒ Configuration
constructor
do initializations.
-
#method_missing(msg, *args) ⇒ Object
return any value stored in @config.
- #user_conf ⇒ Object
Methods included from BasicLogging
#clear_log, is_muted?, #level, #log, mute, #set_level, #set_target, #target
Methods included from Translating
Constructor Details
#initialize(options) ⇒ Configuration
do initializations
32 33 34 35 36 |
# File 'lib/configuration.rb', line 32 def initialize() set_level $log_level set() 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
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/configuration.rb', line 68 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
#dicts ⇒ Object (readonly)
Returns the value of attribute dicts.
65 66 67 |
# File 'lib/configuration.rb', line 65 def dicts @dicts end |
#fdelim ⇒ Object (readonly)
Returns the value of attribute fdelim.
65 66 67 |
# File 'lib/configuration.rb', line 65 def fdelim @fdelim end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
65 66 67 |
# File 'lib/configuration.rb', line 65 def fields @fields end |
#placeholders ⇒ Object (readonly)
Returns the value of attribute placeholders.
65 66 67 |
# File 'lib/configuration.rb', line 65 def placeholders @placeholders end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
65 66 67 |
# File 'lib/configuration.rb', line 65 def template @template end |
Instance Method Details
#user_conf ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/configuration.rb', line 38 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 debug 'user cofiguration shall be ' << config debug 'reading defaults from ' << @@config_file if(File.exist?(@@config_file) ) File.open(config, 'w+') {|co| co.write(File.read(@@config_file))} info("Created user-version of the configuration-file in\n\t" << config) else warn(@@config_file.dup << ' does not exist!') #----------- write default configuration to file -------- give_up end rescue Exception => ex error('Cannot create the configuration: ' << ex.) give_up end end return config end |