Class: ConfCheck
- Inherits:
-
Object
- Object
- ConfCheck
- Includes:
- BasicLogging, Translating
- Defined in:
- lib/confcheck.rb
Constant Summary collapse
- @@RD =
File.(File.dirname(__FILE__) ) + File::SEPARATOR
Constants included from BasicLogging
BasicLogging::DEBUG, BasicLogging::ERROR, BasicLogging::FATAL, BasicLogging::INFO, BasicLogging::Levels, BasicLogging::UNKNOWN, BasicLogging::WARN
Instance Attribute Summary
Attributes included from BasicLogging
Instance Method Summary collapse
-
#diffs(conf = :user) ⇒ Object
Return the differences; by default those that indicate the changes needed in the user-configuration so that it contains the same keys as the ‘global’ or ‘original’ version of the configuration.
-
#initialize ⇒ ConfCheck
constructor
A new instance of ConfCheck.
-
#write_user_conf ⇒ Object
Make a backup-copy of the current user-coniguration.
Methods included from BasicLogging
is_muted?, #log, mute, #set_level, #set_target
Methods included from Translating
Constructor Details
#initialize ⇒ ConfCheck
Returns a new instance of ConfCheck.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/confcheck.rb', line 30 def initialize @orig_conf = "#{@@RD}config" if $CONF.has_user_conf begin @orig_keys = YAML::load_file(@orig_conf).keys rescue Exception => ex warn(trl("Cannot load the configuration-file %s") %(@orig_conf) << " (" << ex. << ")"); end @user_keys = $CONF.keys else @user_conf = $CONF.user_configuration end end |
Instance Method Details
#diffs(conf = :user) ⇒ Object
Return the differences; by default those that indicate the changes needed in the user-configuration so that it contains the same keys as the ‘global’ or ‘original’ version of the configuration.
47 48 49 50 51 52 53 54 |
# File 'lib/confcheck.rb', line 47 def diffs(conf = :user) test_keys = (conf == :user ? @user_keys : @orig_keys) comp_keys = (conf == :user ? @orig_keys : @user_keys) if(test_keys && comp_keys) return {:missing => comp_keys - test_keys, :additional => test_keys - comp_keys} end return nil end |
#write_user_conf ⇒ Object
Make a backup-copy of the current user-coniguration. Overwrite the current user-configuration with a copy of the current global/original configuration-file or create a new user-configuration.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/confcheck.rb', line 59 def write_user_conf if(@user_conf && File.exist?(@user_conf)) backup = @user_conf.dup << '_bak' File.open backup, 'w' do |bc| File.open @user_conf, 'r' do |uc| while uc.gets("\n") do bc << $_ end end end end copy_file @orig_conf, @user_conf end |