Class: Kafo::ExitHandler
- Inherits:
-
Object
- Object
- Kafo::ExitHandler
- Defined in:
- lib/kafo/exit_handler.rb
Instance Attribute Summary collapse
-
#cleanup_paths ⇒ Object
Returns the value of attribute cleanup_paths.
-
#exit_code ⇒ Object
Returns the value of attribute exit_code.
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
- #cleanup ⇒ Object
- #error_codes ⇒ Object
- #exit(code, &block) ⇒ Object
-
#initialize ⇒ ExitHandler
constructor
A new instance of ExitHandler.
- #register_cleanup_path(path) ⇒ Object
- #translate_exit_code(code) ⇒ Object
Constructor Details
#initialize ⇒ ExitHandler
Returns a new instance of ExitHandler.
5 6 7 8 9 |
# File 'lib/kafo/exit_handler.rb', line 5 def initialize @cleanup_paths = [] @exit_code = 0 @logger = KafoConfigure.logger end |
Instance Attribute Details
#cleanup_paths ⇒ Object
Returns the value of attribute cleanup_paths.
3 4 5 |
# File 'lib/kafo/exit_handler.rb', line 3 def cleanup_paths @cleanup_paths end |
#exit_code ⇒ Object
Returns the value of attribute exit_code.
3 4 5 |
# File 'lib/kafo/exit_handler.rb', line 3 def exit_code @exit_code end |
#logger ⇒ Object
Returns the value of attribute logger.
3 4 5 |
# File 'lib/kafo/exit_handler.rb', line 3 def logger @logger end |
Instance Method Details
#cleanup ⇒ Object
44 45 46 47 48 49 50 |
# 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 ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# 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 } end |
#exit(code, &block) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/kafo/exit_handler.rb', line 26 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) ⇒ Object
52 53 54 |
# File 'lib/kafo/exit_handler.rb', line 52 def register_cleanup_path(path) self.cleanup_paths<< path end |
#translate_exit_code(code) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/kafo/exit_handler.rb', line 35 def translate_exit_code(code) return code if code.is_a?(Fixnum) if error_codes.has_key?(code) return error_codes[code] else raise "Unknown code #{code}" end end |