Class: DreamhostPersonalBackup::Configurator

Inherits:
Object
  • Object
show all
Defined in:
lib/backup/configurator.rb

Constant Summary collapse

VALID_CONFIG_PARAMETERS =
[:user, :host, :logfile, :targets, :notifyemail, :logrotationsizeinbytes, :logkeepcount]
DEFAULT_CONFIG_FILE =
'~/.dreamhost_personal_backup/default_config.yml'
DEFAULT_LOG_SIZE =
105000000
DEFAULT_LOG_KEEP_COUNT =
3

Class Method Summary collapse

Class Method Details

.process_config_file(config_file_path = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/backup/configurator.rb', line 17

def self.process_config_file(config_file_path = nil)
  config_file_path ||= DEFAULT_CONFIG_FILE
  config_file = File.expand_path(config_file_path)

  raise DreamhostPersonalBackup::ConfigFileNotFound unless File.file?(config_file)

  config_parameters = Hash.new

  config_file = YAML.load_file(config_file)
  config_file.each do |config_key, config_value|
    config_parameter = config_key.downcase.to_sym

    raise DreamhostPersonalBackup::InvalidConfigParameter unless VALID_CONFIG_PARAMETERS.include?(config_parameter)

    config_parameters[config_parameter] = config_value
  end

  config_parameters = set_default_values_if_necessary(config_parameters)

  config_parameters[:logger] = create_logger(config_parameters)

  config_parameters
end