Class: Configuration
- Inherits:
-
Object
- Object
- Configuration
- 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
-
#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 Logging
#debout, #formatter, #init_logger, #log_level=, #log_level?, #log_target=
Methods included from Translating
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() init_logger(STDOUT) @log.level = $log_level set() @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
#dicts ⇒ Object (readonly)
Returns the value of attribute dicts.
64 65 66 |
# File 'lib/configuration.rb', line 64 def dicts @dicts end |
#fdelim ⇒ Object (readonly)
Returns the value of attribute fdelim.
64 65 66 |
# File 'lib/configuration.rb', line 64 def fdelim @fdelim end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
64 65 66 |
# File 'lib/configuration.rb', line 64 def fields @fields end |
#placeholders ⇒ Object (readonly)
Returns the value of attribute placeholders.
64 65 66 |
# File 'lib/configuration.rb', line 64 def placeholders @placeholders end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
64 65 66 |
# File 'lib/configuration.rb', line 64 def template @template end |
Instance Method Details
#user_conf ⇒ Object
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.) give_up end end return config end |