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
protected
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
Use the arguments passed on the command-line along with those defined by the client application and Vedeu’s defaults to configure the client application.
- #debug_execute! ⇒ void
- #execute! ⇒ void
-
#initialize(argv = [], stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ Launcher
constructor
Returns a new instance of Vedeu::Launcher.
-
#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
Returns a new instance of Vedeu::Launcher.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vedeu/launcher.rb', line 33 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, protected)
Returns The command line arguments provided.
78 79 80 |
# File 'lib/vedeu/launcher.rb', line 78 def argv @argv end |
#exit_code ⇒ Fixnum (readonly)
Return value indicating successful execution (0) or an error occurred (1).
14 15 16 |
# File 'lib/vedeu/launcher.rb', line 14 def exit_code @exit_code end |
Class Method Details
.execute!(argv = [], stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/vedeu/launcher.rb', line 17 def self.execute!(argv = [], stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) new(argv, stdin, stdout, stderr, kernel).debug_execute! end |
Instance Method Details
#configuration ⇒ Vedeu::Configuration (private)
Use the arguments passed on the command-line along with those defined by the client application and Vedeu’s defaults to configure the client application.
100 101 102 103 104 105 106 |
# File 'lib/vedeu/launcher.rb', line 100 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.
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/vedeu/launcher.rb', line 47 def debug_execute! if configuration.debug? Vedeu.debug { execute! } else execute! end terminate! end |
#execute! ⇒ void
This method returns an undefined value.
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/vedeu/launcher.rb', line 60 def execute! $stdin = @stdin $stdout = @stdout $stderr = @stderr Vedeu::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 92 93 |
# File 'lib/vedeu/launcher.rb', line 85 def terminate! Vedeu.log(type: :info, message: 'Exiting gracefully.') $stdin = STDIN $stdout = STDOUT $stderr = STDERR @kernel.exit(exit_code) end |