Class: Gloo::App::Engine
- Inherits:
-
Object
- Object
- Gloo::App::Engine
- Defined in:
- lib/gloo/app/engine.rb
Constant Summary collapse
- TEST_LIB_NAME =
Constants for the name of the test library. This is the short name as it would be used with the load verb.
'test'
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#context_object ⇒ Object
Returns the value of attribute context_object.
-
#converter ⇒ Object
Returns the value of attribute converter.
-
#dictionary ⇒ Object
readonly
Returns the value of attribute dictionary.
-
#event_manager ⇒ Object
Returns the value of attribute event_manager.
-
#exec_env ⇒ Object
Returns the value of attribute exec_env.
-
#ext_manager ⇒ Object
readonly
Returns the value of attribute ext_manager.
-
#factory ⇒ Object
readonly
Returns the value of attribute factory.
-
#heap ⇒ Object
readonly
Returns the value of attribute heap.
-
#last_cmd ⇒ Object
Returns the value of attribute last_cmd.
-
#lib_manager ⇒ Object
readonly
Returns the value of attribute lib_manager.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
-
#persist_man ⇒ Object
Returns the value of attribute persist_man.
-
#platform ⇒ Object
readonly
Returns the value of attribute platform.
-
#running ⇒ Object
readonly
Returns the value of attribute running.
-
#running_app ⇒ Object
readonly
Returns the value of attribute running_app.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
-
#app_running? ⇒ Boolean
Is there a running app?.
-
#err(msg, backtrace = nil) ⇒ Object
Report an error.
-
#error? ⇒ Boolean
Did the last command result in an error?.
-
#handle_exception(ex) ⇒ Object
Handle an unanticipated Ruby exception caught at one of the engine's rescue points.
-
#initialize(context) ⇒ Engine
constructor
Set up the engine with basic elements.
-
#last_cmd_blank? ⇒ Boolean
Is the last command entered blank?.
-
#load_files ⇒ Object
Load all file specified in the CLI.
-
#log_exception(ex) ⇒ Object
Log an exception.
-
#loop ⇒ Object
Prompt, Get input, process.
-
#open_start_file ⇒ Object
Get the setting for the start_with file and open it.
-
#process_cmd(cmd = nil) ⇒ Object
Process the command.
-
#quit ⇒ Object
Do any clean up and quit.
-
#reset_state ⇒ Object
Reset the engine state.
-
#restart ⇒ Object
Restart the engine with the same settings and the same mode (with files, etc).
-
#run ⇒ Object
Run in interactive mode.
-
#run_files ⇒ Object
Run files specified on the CLI.
-
#run_keep_alive ⇒ Object
Run in Embedded mode, which means we'll start the engine, but wait for external inputs.
-
#run_mode ⇒ Object
Run gloo in the selected mode.
-
#run_test ⇒ Object
Run in gloo unit test mode.
-
#run_version ⇒ Object
Show the version information and then quit.
-
#start ⇒ Object
Start the engine.
-
#start_running_app(obj) ⇒ Object
Set the running app object within gloo.
-
#stop_running ⇒ Object
Request the engine to stop running.
-
#stop_running_app ⇒ Object
Stop the running app object within gloo.
-
#theme ⇒ Object
Get the active theme.
Constructor Details
#initialize(context) ⇒ Engine
Set up the engine with basic elements.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gloo/app/engine.rb', line 30 def initialize( context ) @args = Args.new( self, context.params ) @settings = Settings.new( self, context.user_root ) # Platform (and its theme) needs to be ready before Log is # constructed - Log reads engine.theme, which reads through # to platform.theme, in its own initialize. @platform = context.platform @platform.theme = Gloo::App::Theme.new( @settings.theme ) @log = context.log.new( self, @args.quiet? ) @log.debug "log (class: #{@log.class.name}) in use ..." @log.debug "platform (class: #{@platform.class.name}) in use ..." @handling_exception = false @handling_error = false @log.debug 'engine intialized...' end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
21 22 23 |
# File 'lib/gloo/app/engine.rb', line 21 def args @args end |
#context_object ⇒ Object
Returns the value of attribute context_object.
24 25 26 |
# File 'lib/gloo/app/engine.rb', line 24 def context_object @context_object end |
#converter ⇒ Object
Returns the value of attribute converter.
24 25 26 |
# File 'lib/gloo/app/engine.rb', line 24 def converter @converter end |
#dictionary ⇒ Object (readonly)
Returns the value of attribute dictionary.
21 22 23 |
# File 'lib/gloo/app/engine.rb', line 21 def dictionary @dictionary end |
#event_manager ⇒ Object
Returns the value of attribute event_manager.
24 25 26 |
# File 'lib/gloo/app/engine.rb', line 24 def event_manager @event_manager end |
#exec_env ⇒ Object
Returns the value of attribute exec_env.
24 25 26 |
# File 'lib/gloo/app/engine.rb', line 24 def exec_env @exec_env end |
#ext_manager ⇒ Object (readonly)
Returns the value of attribute ext_manager.
21 22 23 |
# File 'lib/gloo/app/engine.rb', line 21 def ext_manager @ext_manager end |
#factory ⇒ Object (readonly)
Returns the value of attribute factory.
21 22 23 |
# File 'lib/gloo/app/engine.rb', line 21 def factory @factory end |
#heap ⇒ Object (readonly)
Returns the value of attribute heap.
21 22 23 |
# File 'lib/gloo/app/engine.rb', line 21 def heap @heap end |
#last_cmd ⇒ Object
Returns the value of attribute last_cmd.
24 25 26 |
# File 'lib/gloo/app/engine.rb', line 24 def last_cmd @last_cmd end |
#lib_manager ⇒ Object (readonly)
Returns the value of attribute lib_manager.
21 22 23 |
# File 'lib/gloo/app/engine.rb', line 21 def lib_manager @lib_manager end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
20 21 22 |
# File 'lib/gloo/app/engine.rb', line 20 def log @log end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
21 22 23 |
# File 'lib/gloo/app/engine.rb', line 21 def mode @mode end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
21 22 23 |
# File 'lib/gloo/app/engine.rb', line 21 def parser @parser end |
#persist_man ⇒ Object
Returns the value of attribute persist_man.
24 25 26 |
# File 'lib/gloo/app/engine.rb', line 24 def persist_man @persist_man end |
#platform ⇒ Object (readonly)
Returns the value of attribute platform.
21 22 23 |
# File 'lib/gloo/app/engine.rb', line 21 def platform @platform end |
#running ⇒ Object (readonly)
Returns the value of attribute running.
21 22 23 |
# File 'lib/gloo/app/engine.rb', line 21 def running @running end |
#running_app ⇒ Object (readonly)
Returns the value of attribute running_app.
20 21 22 |
# File 'lib/gloo/app/engine.rb', line 20 def running_app @running_app end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
20 21 22 |
# File 'lib/gloo/app/engine.rb', line 20 def settings @settings end |
Instance Method Details
#app_running? ⇒ Boolean
Is there a running app?
293 294 295 |
# File 'lib/gloo/app/engine.rb', line 293 def app_running? return @running_app ? true : false end |
#err(msg, backtrace = nil) ⇒ Object
Report an error. Write it to the log and set the heap error value. Always logged; runs the on_error script (if any) unless we're already inside one, so a broken handler can't loop.
328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/gloo/app/engine.rb', line 328 def err( msg, backtrace=nil ) @log.error msg @heap.error.set_to msg return if @handling_error @handling_error = true begin @event_manager.on_error( msg, backtrace ) ensure @handling_error = false end end |
#error? ⇒ Boolean
Did the last command result in an error?
318 319 320 |
# File 'lib/gloo/app/engine.rb', line 318 def error? return !@heap.error.value.nil? end |
#handle_exception(ex) ⇒ Object
Handle an unanticipated Ruby exception caught at one of the engine's rescue points. Always logged; runs the on_exception script (if any) unless we're already inside one, so a broken handler can't loop.
360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/gloo/app/engine.rb', line 360 def handle_exception ex backtrace = format_backtrace( ex ) @log.error ex. @log.error backtrace return if @handling_exception @handling_exception = true begin @event_manager.on_exception( ex., backtrace ) ensure @handling_exception = false end end |
#last_cmd_blank? ⇒ Boolean
Is the last command entered blank?
212 213 214 215 216 217 |
# File 'lib/gloo/app/engine.rb', line 212 def last_cmd_blank? return true if @last_cmd.nil? return true if @last_cmd.strip.empty? return false end |
#load_files ⇒ Object
Load all file specified in the CLI.
147 148 149 |
# File 'lib/gloo/app/engine.rb', line 147 def load_files @args.files.each { |f| @persist_man.load( f ) } end |
#log_exception(ex) ⇒ Object
Log an exception. This function does not log the full backtrace, but does write part of it to the log.
347 348 349 350 351 352 |
# File 'lib/gloo/app/engine.rb', line 347 def log_exception ex backtrace = format_backtrace( ex ) @log.error backtrace err( ex., backtrace) end |
#loop ⇒ Object
Prompt, Get input, process.
222 223 224 225 226 227 |
# File 'lib/gloo/app/engine.rb', line 222 def loop while @running @last_cmd = @platform.prompt.ask process_cmd end end |
#open_start_file ⇒ Object
Get the setting for the start_with file and open it. In App mode, the configured start_with setting is ignored - we always look for a start.gloo at the root of the app (project_path was already overridden to the app path).
199 200 201 202 203 204 205 206 207 |
# File 'lib/gloo/app/engine.rb', line 199 def open_start_file if @mode == Mode::APP @persist_man.load( 'start' ) return end name = @settings.start_with @persist_man.load( name ) if name end |
#process_cmd(cmd = nil) ⇒ Object
Process the command.
232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/gloo/app/engine.rb', line 232 def process_cmd cmd=nil @last_cmd = cmd if cmd if last_cmd_blank? @platform.clear_screen return end begin @parser.run @last_cmd rescue => e handle_exception e end end |
#quit ⇒ Object
Do any clean up and quit.
257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/gloo/app/engine.rb', line 257 def quit if app_running? @log.debug 'stopping running app...' stop_running_app end @log.debug 'triggering on_quit events...' @event_manager.on_quit @log.info 'Gloo engine is quitting...' end |
#reset_state ⇒ Object
Reset the engine state. Clear out anything that needs clearing or resetting to get the engine back to a clean state.
92 93 94 95 96 |
# File 'lib/gloo/app/engine.rb', line 92 def reset_state stop_running_app @heap = Gloo::Core::Heap.new( self ) @persist_man = Gloo::Persist::PersistMan.new( self ) end |
#restart ⇒ Object
Restart the engine with the same settings and the same mode (with files, etc).
102 103 104 105 106 |
# File 'lib/gloo/app/engine.rb', line 102 def restart @log.info 'Restarting the engine...' reset_state run_mode end |
#run ⇒ Object
Run in interactive mode.
171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/gloo/app/engine.rb', line 171 def run # Open default file(s) self.open_start_file # Open any files specifed in args load_files unless @mode == Mode::SCRIPT || @args.quiet? self.loop end quit end |
#run_files ⇒ Object
Run files specified on the CLI. Then quit.
139 140 141 142 |
# File 'lib/gloo/app/engine.rb', line 139 def run_files load_files quit end |
#run_keep_alive ⇒ Object
Run in Embedded mode, which means we'll start the engine, but wait for external inputs.
189 190 191 |
# File 'lib/gloo/app/engine.rb', line 189 def run_keep_alive @log.debug 'Running in Embedded mode…' end |
#run_mode ⇒ Object
Run gloo in the selected mode.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/gloo/app/engine.rb', line 116 def run_mode @log.info "Running gloo in #{@mode} mode" if @mode == Mode::VERSION run_version elsif @mode == Mode::SCRIPT run_files elsif @mode == Mode::EMBED run_keep_alive elsif @mode == Mode::APP @settings.override_project_path @args.app_path run elsif @mode == Mode::TEST run_test else run end end |
#run_test ⇒ Object
Run in gloo unit test mode.
154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/gloo/app/engine.rb', line 154 def run_test @log.debug 'Running in Test mode…' begin @lib_manager.load_lib TEST_LIB_NAME TestRunner.new( self, @args.files ).run rescue => ex handle_exception ex end @log.debug 'Tests complete.' quit end |
#run_version ⇒ Object
Show the version information and then quit.
305 306 307 308 |
# File 'lib/gloo/app/engine.rb', line 305 def run_version @platform.show Info.full_version unless @args.quiet? quit end |
#start ⇒ Object
Start the engine. Load object and verb definitions and setup engine elements.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/gloo/app/engine.rb', line 64 def start @log.debug 'starting the engine...' @log.debug Gloo::App::Info.display_title @mode = @args.detect_mode @running = true @dictionary = Gloo::Core::Dictionary.get @parser = Gloo::Core::Parser.new( self ) @heap = Gloo::Core::Heap.new( self ) @factory = Gloo::Core::Factory.new( self ) @persist_man = Gloo::Persist::PersistMan.new( self ) @event_manager = Gloo::Core::EventManager.new( self ) @ext_manager = Gloo::Plugin::ExtManager.new( self ) @lib_manager = Gloo::Plugin::LibManager.new( self ) @exec_env = Gloo::Exec::ExecEnv.new( self ) @converter = Gloo::Convert::Converter.new( self ) @log.info 'The gloo engine has started' run_mode end |
#start_running_app(obj) ⇒ Object
Set the running app object within gloo.
277 278 279 280 |
# File 'lib/gloo/app/engine.rb', line 277 def start_running_app( obj ) @running_app = Gloo::App::RunningApp.new( obj, self ) @running_app.start end |
#stop_running ⇒ Object
Request the engine to stop running.
250 251 252 |
# File 'lib/gloo/app/engine.rb', line 250 def stop_running @running = false end |
#stop_running_app ⇒ Object
Stop the running app object within gloo.
285 286 287 288 |
# File 'lib/gloo/app/engine.rb', line 285 def stop_running_app @running_app.stop if @running_app @running_app = nil end |
#theme ⇒ Object
Get the active theme. Platform is the single source of truth for it (Prompt/Table only hold a @platform reference, not an @engine one) - this just reads through to that, rather than keeping a second ivar that could drift out of sync if something reassigns platform.theme directly.
56 57 58 |
# File 'lib/gloo/app/engine.rb', line 56 def theme return @platform.theme end |