Class: UBSafe::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ubsafe/ubsafe_config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/ubsafe/ubsafe_config.rb', line 10

def options
  @options
end

Class Method Details

.configUBSafe::Config

Get configuration settings

Returns:



19
20
21
22
23
24
# File 'lib/ubsafe/ubsafe_config.rb', line 19

def config
  if (not defined?(@@config_instance)) or @@config_instance.nil?
    @@config_instance = UBSafe::Config.new
  end
  return @@config_instance
end

.resetObject

Reset the configuration settings



29
30
31
# File 'lib/ubsafe/ubsafe_config.rb', line 29

def reset
  @@config_instance = nil
end

Instance Method Details

#full_options(backup_name) ⇒ Hash

Get the full set of configuration options for the specified backup

Parameters:

  • backup_name (Symbol)

Returns:

  • (Hash)

    (Flattened?) hash with all the options for this backup. Nil if this backup is not present or enabled.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ubsafe/ubsafe_config.rb', line 70

def full_options(backup_name)
  backup_options = {}
  # Get backup defaults
  backup_options.merge!(@options[:backup_defaults].dup_contents_1_level)
  # Get the specific backup definition
  unless @options[:backups].has_key?(backup_name.to_sym)
    @logger.fatal("The backup name specified '#{backup_name}' has no configuration defined in #{@options[:config_file]}") 
    raise Exception.new("Non-existent backup specified '#{backup_name}'")
  end
  backup_options.merge!(@options[:backups][backup_name.to_sym].dup_contents_1_level)
  return nil unless backup_options[:enabled]
  backup_options[:backup_name] = backup_name.to_s unless backup_options[:backup_name]
  # Expand the backup host reference
  selected_host = backup_options[:backup_host]
  backup_options.merge!(@options[:backup_hosts][selected_host].dup_contents_1_level)
  # Expand the backup type reference
  selected_backup_type = backup_options[:backup_type]
  backup_options.merge!(@options[:backup_types][selected_backup_type].dup_contents_1_level)
  return backup_options
end

#load(args = nil) ⇒ Object

Load a Config instance

Parameters:

  • args (Array) (defaults to: nil)

    Command-line arguments



53
54
55
56
57
58
59
60
61
62
# File 'lib/ubsafe/ubsafe_config.rb', line 53

def load(args = nil)
  @options[:config_file] = ENV['UBSAFE_CONFIG_FILE'] unless ENV['UBSAFE_CONFIG_FILE'].nil?
  #puts "UBConfig.load After env check @options #{@options.inspect}"
  @options.merge!(parse_args(args))
  #puts "UBConfig.load After merge @options #{@options.inspect}"
  if @options[:config_file]
    @options.merge!(load_config_file(@options[:config_file]))
  end
  configure_logging
end

#logLogging::Logger

Get logger

Returns:

  • (Logging::Logger)

    Common logger instance



95
96
97
# File 'lib/ubsafe/ubsafe_config.rb', line 95

def log
  return defined?(@logger) ? @logger : nil
end