class Kafo::ExitHandler

Attributes

cleanup_paths[RW]
exit_code[RW]
logger[RW]

Public Class Methods

new() click to toggle source
# File lib/kafo/exit_handler.rb, line 5
def initialize
  @cleanup_paths = []
  @exit_code = 0
  @logger = KafoConfigure.logger
end

Public Instance Methods

cleanup() click to toggle source
# File lib/kafo/exit_handler.rb, line 45
def cleanup
  # make sure default values are removed from /tmp
  (self.cleanup_paths + ['/tmp/default_values.yaml']).each do |file|
    logger.debug "Cleaning #{file}"
    FileUtils.rm_rf(file)
  end
end
error_codes() click to toggle source
# File lib/kafo/exit_handler.rb, line 11
def error_codes
  @error_codes ||= {
      :invalid_system => 20,
      :invalid_values => 21,
      :manifest_error => 22,
      :no_answer_file => 23,
      :unknown_module => 24,
      :defaults_error => 25,
      :unset_scenario => 26,
      :scenario_error => 27,
      :missing_argument => 28,
      :insufficient_permissions => 29,
      :puppet_version_error => 30
  }
end
exit(code, &block) click to toggle source
# File lib/kafo/exit_handler.rb, line 27
def exit(code, &block)
  @exit_code = translate_exit_code(code)
  block.call if block
  KafoConfigure.logger.debug "Exit with status code: #{@exit_code} (signal was #{code})"
  KafoConfigure.logger.dump_errors unless KafoConfigure.verbose
  cleanup
  Kernel.exit(@exit_code)
end
register_cleanup_path(path) click to toggle source
# File lib/kafo/exit_handler.rb, line 53
def register_cleanup_path(path)
  self.cleanup_paths<< path
end
translate_exit_code(code) click to toggle source
# File lib/kafo/exit_handler.rb, line 36
def translate_exit_code(code)
  return code if code.is_a?(Integer)
  if error_codes.has_key?(code)
    return error_codes[code]
  else
    raise "Unknown code #{code}"
  end
end