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.
-
#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.
-
#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.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Class Method Summary collapse
-
.deserialize(data) ⇒ Object
Deserialize the Engine data.
Instance Method Summary collapse
-
#err(msg) ⇒ 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.
-
#loop ⇒ Object
Prompt, Get input, process.
-
#open_start_file ⇒ Object
Get the setting for the start_with file and open it.
-
#prep_serialize ⇒ Object
Prepare for serialization by removing any file references.
-
#process_cmd ⇒ Object
Process the command.
-
#quit ⇒ Object
Do any clean up and quit.
-
#restore_after_deserialization ⇒ Object
Restore the engine after deserialization.
-
#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.
-
#serialize ⇒ Object
Get the serialized version of this Engine.
-
#start ⇒ Object
Start the engine.
-
#stop_running ⇒ Object
Request the engine to stop running.
Constructor Details
#initialize(context) ⇒ Engine
Set up the engine with basic elements.
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/gloo/app/engine.rb', line 23 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.
17 18 19 |
# File 'lib/gloo/app/engine.rb', line 17 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.
17 18 19 |
# File 'lib/gloo/app/engine.rb', line 17 def event_manager @event_manager end |
#exec_env ⇒ Object
Returns the value of attribute exec_env.
17 18 19 |
# File 'lib/gloo/app/engine.rb', line 17 def exec_env @exec_env 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.
17 18 19 |
# File 'lib/gloo/app/engine.rb', line 17 def last_cmd @last_cmd 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.
17 18 19 |
# File 'lib/gloo/app/engine.rb', line 17 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 |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
14 15 16 |
# File 'lib/gloo/app/engine.rb', line 14 def settings @settings end |
Class Method Details
.deserialize(data) ⇒ Object
Deserialize the Engine data.
84 85 86 87 88 |
# File 'lib/gloo/app/engine.rb', line 84 def self.deserialize data e = Marshal::load( data ) e.restore_after_deserialization return e end |
Instance Method Details
#err(msg) ⇒ Object
Report an error. Write it to the log and set the heap error value.
240 241 242 243 |
# File 'lib/gloo/app/engine.rb', line 240 def err( msg ) @log.error msg @heap.error.set_to msg end |
#error? ⇒ Boolean
Did the last command result in an error?
232 233 234 |
# File 'lib/gloo/app/engine.rb', line 232 def error? return !@heap.error.value.nil? end |
#last_cmd_blank? ⇒ Boolean
Is the last command entered blank?
170 171 172 173 174 175 |
# File 'lib/gloo/app/engine.rb', line 170 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.
130 131 132 |
# File 'lib/gloo/app/engine.rb', line 130 def load_files @args.files.each { |f| @persist_man.load( f ) } end |
#loop ⇒ Object
Prompt, Get input, process.
180 181 182 183 184 185 |
# File 'lib/gloo/app/engine.rb', line 180 def loop while @running @last_cmd = @platform.prompt_cmd process_cmd end end |
#open_start_file ⇒ Object
Get the setting for the start_with file and open it.
162 163 164 165 |
# File 'lib/gloo/app/engine.rb', line 162 def open_start_file name = @settings.start_with @persist_man.load( name ) if name end |
#prep_serialize ⇒ Object
Prepare for serialization by removing any file references. Without this, the engine cannot be serialized.
69 70 71 |
# File 'lib/gloo/app/engine.rb', line 69 def prep_serialize @log.prep_serialize end |
#process_cmd ⇒ Object
Process the command.
190 191 192 193 194 195 196 197 |
# File 'lib/gloo/app/engine.rb', line 190 def process_cmd if last_cmd_blank? @platform.clear_screen return end @parser.run @last_cmd end |
#quit ⇒ Object
Do any clean up and quit.
209 210 211 |
# File 'lib/gloo/app/engine.rb', line 209 def quit @log.debug 'quitting...' end |
#restore_after_deserialization ⇒ Object
Restore the engine after deserialization.
93 94 95 |
# File 'lib/gloo/app/engine.rb', line 93 def restore_after_deserialization @log.restore_after_deserialization end |
#run ⇒ Object
Run in interactive mode.
137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/gloo/app/engine.rb', line 137 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.
122 123 124 125 |
# File 'lib/gloo/app/engine.rb', line 122 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.
155 156 157 |
# File 'lib/gloo/app/engine.rb', line 155 def run_keep_alive @log.debug 'Running in Embedded mode...' end |
#run_mode ⇒ Object
Run gloo in the selected mode.
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/gloo/app/engine.rb', line 104 def run_mode @log.debug "running gloo in #{@mode} mode" if @mode == Mode::VERSION run_version elsif @mode == Mode::SCRIPT run_files elsif @mode == Mode::EMBED run_keep_alive else run end end |
#run_version ⇒ Object
Show the version information and then quit.
220 221 222 223 |
# File 'lib/gloo/app/engine.rb', line 220 def run_version @platform.show Info.full_version unless @args.quiet? quit end |
#serialize ⇒ Object
Get the serialized version of this Engine.
76 77 78 79 |
# File 'lib/gloo/app/engine.rb', line 76 def serialize prep_serialize Marshal::dump( self ) end |
#start ⇒ Object
Start the engine. Load object and verb definitions and setup engine elements.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gloo/app/engine.rb', line 40 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 ) @exec_env = Gloo::Exec::ExecEnv.new( self ) @converter = Gloo::Convert::Converter.new( self ) @log.debug 'the engine has started' run_mode end |
#stop_running ⇒ Object
Request the engine to stop running.
202 203 204 |
# File 'lib/gloo/app/engine.rb', line 202 def stop_running @running = false end |