Class: Vedeu::Launcher
- Inherits:
-
Object
- Object
- Vedeu::Launcher
- Defined in:
- lib/vedeu/runtime/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
-
.execute!(argv = [], stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ Object
:nocov:.
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
:nocov: If debugging is enabled, execute the application within the debugging context.
-
#execute! ⇒ void
Alters the STD to those requested by the client application, then starts the application.
-
#initialize(argv = [], stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ Vedeu::Launcher
constructor
Returns a new instance of Vedeu::Launcher.
-
#terminate! ⇒ void
private
:nocov: Terminates the application after resetting $stdin, $stdout and $stderr.
Constructor Details
#initialize(argv = [], stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ Vedeu::Launcher
Returns a new instance of Vedeu::Launcher.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/vedeu/runtime/launcher.rb', line 34 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.
93 94 95 |
# File 'lib/vedeu/runtime/launcher.rb', line 93 def argv @argv end |
#exit_code ⇒ Fixnum (readonly)
Return value indicating successful execution (0) or an error occurred (1).
13 14 15 |
# File 'lib/vedeu/runtime/launcher.rb', line 13 def exit_code @exit_code end |
Class Method Details
.execute!(argv = [], stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ Object
:nocov:
17 18 19 20 21 22 23 |
# File 'lib/vedeu/runtime/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.
117 118 119 120 121 122 123 |
# File 'lib/vedeu/runtime/launcher.rb', line 117 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.
:nocov: If debugging is enabled, execute the application within the debugging context. At the moment, this simple uses ‘ruby-prof’ to profile the running application.
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/vedeu/runtime/launcher.rb', line 53 def debug_execute! if configuration.debug? Vedeu.debug { execute! } else execute! end terminate! end |
#execute! ⇒ void
This method returns an undefined value.
Alters the STD to those requested by the client application, then starts the application. If an uncaught exception occurs during the application runtime, we exit ungracefully with any error message(s).
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/vedeu/runtime/launcher.rb', line 71 def execute! $stdin = @stdin $stdout = @stdout $stderr = @stderr Vedeu::Runtime::Application.start(configuration) @exit_code = 0 rescue StandardError => uncaught_exception Vedeu.log_stdout(type: :error, message: uncaught_exception.) if configuration.debug? Vedeu.log_stdout(type: :error, message: uncaught_exception.backtrace.join("\n")) end end |
#terminate! ⇒ void (private)
This method returns an undefined value.
:nocov: Terminates the application after resetting $stdin, $stdout and $stderr.
101 102 103 104 105 106 107 108 109 |
# File 'lib/vedeu/runtime/launcher.rb', line 101 def terminate! Vedeu.log(type: :info, message: 'Exiting gracefully.') $stdin = STDIN $stdout = STDOUT $stderr = STDERR @kernel.exit(exit_code) end |