Class: Configuration
- Inherits:
-
Object
- Object
- Configuration
- Extended by:
- Logging
- Includes:
- File_Checking, Singleton, Translating
- Defined in:
- lib/configuration.rb
Constant Summary collapse
- @@log =
init_logger()
- @@config_file =
default configuration file
File::dirname(__FILE__) << File::Separator << 'config'
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
do initializations.
-
#method_missing(msg, *args) ⇒ Object
return any value stored in @config.
-
#set(options) ⇒ Object
Configure with the command-line arguments.
Methods included from Logging
init_logger, log_level=, log_target=
Methods included from File_Checking
Methods included from Translating
Constructor Details
#initialize ⇒ Configuration
do initializations
44 45 46 47 48 |
# File 'lib/configuration.rb', line 44 def initialize() # Use class-level logger for now. # init_logger() @log = @@log 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
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/configuration.rb', line 76 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 Method Details
#set(options) ⇒ Object
Configure with the command-line arguments.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/configuration.rb', line 51 def set() @log.debug('options are: ' << .to_s ) # User-provided configuration-file? if(['config']) cf = ['config'] msg = check_file(cf, :file, :readable) if(!msg) @@config_file = cf else msg = trl("The file %s " << msg.split[1,100].join(' ')) %msg.split[0] @log.error(trl("ERROR! Unsuitable file") << ' ' << msg) give_up end end @log.debug('config-file is ' << @@config_file) # read defaults from configuration-file co = OpenStruct.new(YAML::load_file(@@config_file)) # merge and overwrite with the command-line arguments @config = co.to_h.merge(.to_h) @log.debug('config is now: ' << @config.to_s ) verify end |