class Kafo::ExitHandler
Attributes
cleanup_paths[RW]
exit_code[RW]
Public Class Methods
new()
click to toggle source
# File lib/kafo/exit_handler.rb, line 5 def initialize @cleanup_paths = [] @exit_code = 0 end
Public Instance Methods
cleanup()
click to toggle source
# File lib/kafo/exit_handler.rb, line 44 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 10 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 26 def exit(code, &block) @exit_code = translate_exit_code(code) block.call if block logger.debug "Exit with status code: #{@exit_code} (signal was #{code})" 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 52 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 35 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
Private Instance Methods
logger()
click to toggle source
# File lib/kafo/exit_handler.rb, line 58 def logger @logger ||= KafoConfigure.logger end