Class: Gloo::App::Engine
- Inherits:
-
Object
- Object
- Gloo::App::Engine
- Defined in:
- lib/gloo/app/engine.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#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?.
-
#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.
-
#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_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.
Constructor Details
#initialize(context) ⇒ Engine
Set up the engine with basic elements.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gloo/app/engine.rb', line 24 def initialize( context ) @args = Args.new( self, context.params ) @settings = Settings.new( self, context.user_root ) @log = context.log.new( self, @args.quiet? ) @log.debug "log (class: #{@log.class.name}) in use ..." @platform = context.platform @log.debug "platform (class: #{@platform.class.name}) in use ..." @log.debug 'engine intialized...' end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
15 16 17 |
# File 'lib/gloo/app/engine.rb', line 15 def args @args end |
#converter ⇒ Object
Returns the value of attribute converter.
18 19 20 |
# File 'lib/gloo/app/engine.rb', line 18 def converter @converter end |
#dictionary ⇒ Object (readonly)
Returns the value of attribute dictionary.
15 16 17 |
# File 'lib/gloo/app/engine.rb', line 15 def dictionary @dictionary end |
#event_manager ⇒ Object
Returns the value of attribute event_manager.
18 19 20 |
# File 'lib/gloo/app/engine.rb', line 18 def event_manager @event_manager end |
#exec_env ⇒ Object
Returns the value of attribute exec_env.
18 19 20 |
# File 'lib/gloo/app/engine.rb', line 18 def exec_env @exec_env end |
#ext_manager ⇒ Object (readonly)
Returns the value of attribute ext_manager.
15 16 17 |
# File 'lib/gloo/app/engine.rb', line 15 def ext_manager @ext_manager end |
#factory ⇒ Object (readonly)
Returns the value of attribute factory.
15 16 17 |
# File 'lib/gloo/app/engine.rb', line 15 def factory @factory end |
#heap ⇒ Object (readonly)
Returns the value of attribute heap.
15 16 17 |
# File 'lib/gloo/app/engine.rb', line 15 def heap @heap end |
#last_cmd ⇒ Object
Returns the value of attribute last_cmd.
18 19 20 |
# File 'lib/gloo/app/engine.rb', line 18 def last_cmd @last_cmd end |
#lib_manager ⇒ Object (readonly)
Returns the value of attribute lib_manager.
15 16 17 |
# File 'lib/gloo/app/engine.rb', line 15 def lib_manager @lib_manager end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
14 15 16 |
# File 'lib/gloo/app/engine.rb', line 14 def log @log end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
15 16 17 |
# File 'lib/gloo/app/engine.rb', line 15 def mode @mode end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
15 16 17 |
# File 'lib/gloo/app/engine.rb', line 15 def parser @parser end |
#persist_man ⇒ Object
Returns the value of attribute persist_man.
18 19 20 |
# File 'lib/gloo/app/engine.rb', line 18 def persist_man @persist_man end |
#platform ⇒ Object (readonly)
Returns the value of attribute platform.
15 16 17 |
# File 'lib/gloo/app/engine.rb', line 15 def platform @platform end |
#running ⇒ Object (readonly)
Returns the value of attribute running.
15 16 17 |
# File 'lib/gloo/app/engine.rb', line 15 def running @running end |
#running_app ⇒ Object (readonly)
Returns the value of attribute running_app.
14 15 16 |
# File 'lib/gloo/app/engine.rb', line 14 def running_app @running_app end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
14 15 16 |
# File 'lib/gloo/app/engine.rb', line 14 def settings @settings end |
Instance Method Details
#app_running? ⇒ Boolean
Is there a running app?
222 223 224 |
# File 'lib/gloo/app/engine.rb', line 222 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.
255 256 257 258 259 260 |
# File 'lib/gloo/app/engine.rb', line 255 def err( msg, backtrace=nil ) @log.error msg @heap.error.set_to msg @event_manager.on_error( msg, backtrace) end |
#error? ⇒ Boolean
Did the last command result in an error?
247 248 249 |
# File 'lib/gloo/app/engine.rb', line 247 def error? return !@heap.error.value.nil? end |
#last_cmd_blank? ⇒ Boolean
Is the last command entered blank?
141 142 143 144 145 146 |
# File 'lib/gloo/app/engine.rb', line 141 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.
101 102 103 |
# File 'lib/gloo/app/engine.rb', line 101 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.
267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/gloo/app/engine.rb', line 267 def log_exception ex # Get the stack trace, and if needed truncate to fit. msg_lines = ex.backtrace if msg_lines.count > 27 msg_lines = msg_lines[0..13] + [ '... truncated ...' ] + msg_lines[-13..-1] end backtrace = msg_lines.join( "\n" ) @log.error backtrace err( ex., backtrace) end |
#loop ⇒ Object
Prompt, Get input, process.
151 152 153 154 155 156 |
# File 'lib/gloo/app/engine.rb', line 151 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.
133 134 135 136 |
# File 'lib/gloo/app/engine.rb', line 133 def open_start_file name = @settings.start_with @persist_man.load( name ) if name end |
#process_cmd(cmd = nil) ⇒ Object
Process the command.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/gloo/app/engine.rb', line 161 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 log_exception e end end |
#quit ⇒ Object
Do any clean up and quit.
186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/gloo/app/engine.rb', line 186 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 |
#run ⇒ Object
Run in interactive mode.
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/gloo/app/engine.rb', line 108 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.
93 94 95 96 |
# File 'lib/gloo/app/engine.rb', line 93 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.
126 127 128 |
# File 'lib/gloo/app/engine.rb', line 126 def run_keep_alive @log.debug 'Running in Embedded mode...' end |
#run_mode ⇒ Object
Run gloo in the selected mode.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/gloo/app/engine.rb', line 72 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 else run end end |
#run_version ⇒ Object
Show the version information and then quit.
234 235 236 237 |
# File 'lib/gloo/app/engine.rb', line 234 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.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/gloo/app/engine.rb', line 41 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.
206 207 208 209 |
# File 'lib/gloo/app/engine.rb', line 206 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.
179 180 181 |
# File 'lib/gloo/app/engine.rb', line 179 def stop_running @running = false end |
#stop_running_app ⇒ Object
Stop the running app object within gloo.
214 215 216 217 |
# File 'lib/gloo/app/engine.rb', line 214 def stop_running_app @running_app.stop if @running_app @running_app = nil end |