Class: Vedeu::Launcher
- Inherits:
-
Object
- Object
- Vedeu::Launcher
- Defined in:
- lib/vedeu/launcher.rb
Overview
This class ensures that STDIN, STDOUT and STDERR point to the correct places. It also handles the initial configuration of the application, the starting of the application, the handling of uncaught exceptions and finally the exiting of the application with the correct exit code.
Instance Attribute Summary collapse
-
#argv ⇒ Array<String>
readonly
private
The command line arguments provided.
-
#exit_code ⇒ Fixnum
readonly
Return value indicating successful execution (0) or an error occurred (1).
Class Method Summary collapse
Instance Method Summary collapse
- #configuration ⇒ Vedeu::Configuration private
- #debug_execute! ⇒ void
- #execute! ⇒ void
- #initialize(argv = [], stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ Launcher constructor
-
#terminate! ⇒ void
private
Terminates the application after resetting $stdin, $stdout and $stderr.
Constructor Details
#initialize(argv = [], stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ Launcher
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vedeu/launcher.rb', line 36 def initialize(argv = [], stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) @argv = argv @stdin = stdin @stdout = stdout @stderr = stderr @kernel = kernel @exit_code = 1 end |
Instance Attribute Details
#argv ⇒ Array<String> (readonly, private)
Returns The command line arguments provided.
80 81 82 |
# File 'lib/vedeu/launcher.rb', line 80 def argv @argv end |
#exit_code ⇒ Fixnum (readonly)
Return value indicating successful execution (0) or an error occurred (1).
15 16 17 |
# File 'lib/vedeu/launcher.rb', line 15 def exit_code @exit_code end |
Class Method Details
.execute!(argv = [], stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/vedeu/launcher.rb', line 18 def self.execute!(argv = [], stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) new(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel).debug_execute! end |
Instance Method Details
#configuration ⇒ Vedeu::Configuration (private)
94 95 96 97 98 99 100 |
# File 'lib/vedeu/launcher.rb', line 94 def configuration Vedeu::Configuration.configure(argv) # Configuration.configure(argv, { stdin: @stdin, # stdout: @stdout, # stderr: @stderr }) end |
#debug_execute! ⇒ void
This method returns an undefined value.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/vedeu/launcher.rb', line 50 def debug_execute! if configuration.debug? Vedeu.debug { execute! } else execute! end terminate! end |
#execute! ⇒ void
This method returns an undefined value.
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/vedeu/launcher.rb', line 63 def execute! $stdin, $stdout, $stderr = @stdin, @stdout, @stderr Application.start(configuration) @exit_code = 0 rescue StandardError => uncaught_exception puts uncaught_exception. puts uncaught_exception.backtrace.join("\n") if configuration.debug? end |
#terminate! ⇒ void (private)
This method returns an undefined value.
Terminates the application after resetting $stdin, $stdout and $stderr.
85 86 87 88 89 90 91 |
# File 'lib/vedeu/launcher.rb', line 85 def terminate! Vedeu.log(type: :info, message: "Exiting gracefully.") $stdin, $stdout, $stderr = STDIN, STDOUT, STDERR @kernel.exit(exit_code) end |