Class: Appifier::Services::Finisher

Inherits:
Object
  • Object
show all
Extended by:
Carioca::Injector
Defined in:
lib/appifier/services/finisher.rb

Overview

Exiter namespace

Constant Summary collapse

EXIT_MAP =
configuration.settings.exit_cases

Class Method Summary collapse

Class Method Details

.do_exit(exit_case: :quiet_exit, more: nil) ⇒ Object

exiter wrapper

Parameters:

  • options (Hash)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/appifier/services/finisher.rb', line 27

def self.do_exit(exit_case: :quiet_exit, more: nil )

  mess = ""
  mess = EXIT_MAP[exit_case][:message] if EXIT_MAP[exit_case].include? :message
  mess << " : " unless mess.empty? or not more
  mess << "#{more}" if more
  if  EXIT_MAP[exit_case][:code] == 0 then
    logger.success mess unless mess.empty?
    exit 0
  else
    logger.fatal mess unless mess.empty?
    exit EXIT_MAP[exit_case][:code]
  end
end

.do_return(return_case: :status_ok, more: nil) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/appifier/services/finisher.rb', line 42

def self.do_return(return_case: :status_ok, more: nil )
  
  data = EXIT_MAP[return_case].clone
  data[:status] = (data[:code]>0)? :failure : :success
  data[:more] = more if more
  return data
end

.terminate(return_case: nil, exit_case: nil, more: nil) ⇒ Object



17
18
19
20
21
# File 'lib/appifier/services/finisher.rb', line 17

def self.terminate(return_case: nil, exit_case: nil, more: nil )
    raise "Case must a return or an exit" if return_case and exit_case
    do_exit( exit_case: exit_case, more: more) if exit_case
    do_return(return_case: return_case, more: more) if return_case
end