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.
-
#help ⇒ Object
Returns the value of attribute help.
-
#last_cmd ⇒ Object
Returns the value of attribute last_cmd.
-
#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.
-
#running ⇒ Object
readonly
Returns the value of attribute running.
Instance Method Summary collapse
-
#clear_screen ⇒ Object
Clear the screen.
-
#default_prompt ⇒ Object
Get the default prompt text.
-
#err(msg) ⇒ Object
Report an error.
-
#error? ⇒ Boolean
Did the last command result in an error?.
-
#initialize(params = []) ⇒ Engine
constructor
Set up the engine with basic elements.
-
#last_cmd_blank? ⇒ Boolean
Is the last command entered blank?.
-
#loop ⇒ Object
Prompt, Get input, process.
-
#open_start_file ⇒ Object
Get the setting for the start_with file and open it.
-
#process_cmd ⇒ Object
Process the command.
-
#prompt_cmd ⇒ Object
Prompt for the next 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_mode ⇒ Object
Run gloo in the selected mode.
-
#run_version ⇒ Object
Show the version information and then quit.
-
#show_help_and_quit ⇒ Object
Show the help information and then quit.
-
#start ⇒ Object
Start the engine.
-
#stop_running ⇒ Object
Request the engine to stop running.
Constructor Details
#initialize(params = []) ⇒ Engine
Set up the engine with basic elements.
26 27 28 29 30 31 32 33 |
# File 'lib/gloo/app/engine.rb', line 26 def initialize( params = [] ) $engine = self @args = Args.new( params ) $settings = Settings.new( ENV[ 'GLOO_ENV' ] ) $log = Log.new( @args.quiet? ) $prompt = TTY::Prompt.new $log.debug 'engine intialized...' end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
18 19 20 |
# File 'lib/gloo/app/engine.rb', line 18 def args @args end |
#converter ⇒ Object
Returns the value of attribute converter.
21 22 23 |
# File 'lib/gloo/app/engine.rb', line 21 def converter @converter end |
#dictionary ⇒ Object (readonly)
Returns the value of attribute dictionary.
19 20 21 |
# File 'lib/gloo/app/engine.rb', line 19 def dictionary @dictionary end |
#event_manager ⇒ Object
Returns the value of attribute event_manager.
20 21 22 |
# File 'lib/gloo/app/engine.rb', line 20 def event_manager @event_manager end |
#exec_env ⇒ Object
Returns the value of attribute exec_env.
21 22 23 |
# File 'lib/gloo/app/engine.rb', line 21 def exec_env @exec_env end |
#factory ⇒ Object (readonly)
Returns the value of attribute factory.
19 20 21 |
# File 'lib/gloo/app/engine.rb', line 19 def factory @factory end |
#heap ⇒ Object (readonly)
Returns the value of attribute heap.
19 20 21 |
# File 'lib/gloo/app/engine.rb', line 19 def heap @heap end |
#help ⇒ Object
Returns the value of attribute help.
21 22 23 |
# File 'lib/gloo/app/engine.rb', line 21 def help @help end |
#last_cmd ⇒ Object
Returns the value of attribute last_cmd.
20 21 22 |
# File 'lib/gloo/app/engine.rb', line 20 def last_cmd @last_cmd end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
18 19 20 |
# File 'lib/gloo/app/engine.rb', line 18 def mode @mode end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
19 20 21 |
# File 'lib/gloo/app/engine.rb', line 19 def parser @parser end |
#persist_man ⇒ Object
Returns the value of attribute persist_man.
20 21 22 |
# File 'lib/gloo/app/engine.rb', line 20 def persist_man @persist_man end |
#running ⇒ Object (readonly)
Returns the value of attribute running.
18 19 20 |
# File 'lib/gloo/app/engine.rb', line 18 def running @running end |
Instance Method Details
#clear_screen ⇒ Object
Clear the screen.
202 203 204 205 206 |
# File 'lib/gloo/app/engine.rb', line 202 def clear_screen @cursor ||= TTY::Cursor print @cursor.clear_screen print @cursor.move_to( 0, 0 ) end |
#default_prompt ⇒ Object
Get the default prompt text.
126 127 128 129 130 131 |
# File 'lib/gloo/app/engine.rb', line 126 def default_prompt dt = DateTime.now d = dt.strftime( '%Y.%m.%d' ) t = dt.strftime( '%I:%M:%S' ) return "#{'gloo'.blue} #{d.yellow} #{t.white} >" end |
#err(msg) ⇒ Object
Report an error. Write it to the log and set the heap error value.
223 224 225 226 |
# File 'lib/gloo/app/engine.rb', line 223 def err( msg ) $log.error msg self.heap.error.set_to msg end |
#error? ⇒ Boolean
Did the last command result in an error?
215 216 217 |
# File 'lib/gloo/app/engine.rb', line 215 def error? return !@heap.error.value.nil? end |
#last_cmd_blank? ⇒ Boolean
Is the last command entered blank?
136 137 138 139 140 141 |
# File 'lib/gloo/app/engine.rb', line 136 def last_cmd_blank? return true if @last_cmd.nil? return true if @last_cmd.strip.empty? return false end |
#loop ⇒ Object
Prompt, Get input, process.
146 147 148 149 150 151 |
# File 'lib/gloo/app/engine.rb', line 146 def loop while @running prompt_cmd process_cmd end end |
#open_start_file ⇒ Object
Get the setting for the start_with file and open it.
111 112 113 114 |
# File 'lib/gloo/app/engine.rb', line 111 def open_start_file name = $settings.start_with @persist_man.load( name ) if name end |
#process_cmd ⇒ Object
Process the command.
156 157 158 159 160 161 162 163 |
# File 'lib/gloo/app/engine.rb', line 156 def process_cmd if last_cmd_blank? clear_screen return end @parser.run @last_cmd end |
#prompt_cmd ⇒ Object
Prompt for the next command.
119 120 121 |
# File 'lib/gloo/app/engine.rb', line 119 def prompt_cmd @last_cmd = $prompt.ask( default_prompt ) end |
#quit ⇒ Object
Do any clean up and quit.
175 176 177 |
# File 'lib/gloo/app/engine.rb', line 175 def quit $log.debug 'quitting...' end |
#run ⇒ Object
Run in interactive mode.
94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/gloo/app/engine.rb', line 94 def run # Open default file(s) self.open_start_file # TODO: open any files specifed in args unless @mode == Mode::SCRIPT || @args.quiet? @cursor = TTY::Cursor self.loop end quit end |
#run_files ⇒ Object
Run files specified on the CLI. Then quit.
86 87 88 89 |
# File 'lib/gloo/app/engine.rb', line 86 def run_files @args.files.each { |f| @persist_man.load( f ) } quit end |
#run_mode ⇒ Object
Run gloo in the selected mode.
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/gloo/app/engine.rb', line 68 def run_mode $log.debug "running gloo in #{@mode} mode" if @mode == Mode::VERSION run_version elsif @mode == Mode::HELP show_help_and_quit elsif @mode == Mode::SCRIPT run_files else run end end |
#run_version ⇒ Object
Show the version information and then quit.
186 187 188 189 |
# File 'lib/gloo/app/engine.rb', line 186 def run_version puts Info.display_title unless @args.quiet? quit end |
#show_help_and_quit ⇒ Object
Show the help information and then quit.
194 195 196 197 |
# File 'lib/gloo/app/engine.rb', line 194 def show_help_and_quit @help.show_app_help quit end |
#start ⇒ Object
Start the engine. Load object and verb definitions and setup engine elements.
39 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 39 def start $log.debug 'starting the engine...' $log.debug Info.display_title @mode = @args.detect_mode @running = true @dictionary = Gloo::Core::Dictionary.instance @dictionary.init @parser = Gloo::Core::Parser.new @heap = Gloo::Core::Heap.new @factory = Gloo::Core::Factory.new @persist_man = Gloo::Persist::PersistMan.new @event_manager = Gloo::Core::EventManager.new @exec_env = Gloo::Exec::ExecEnv.new @help = Gloo::App::Help.new @converter = Gloo::Convert::Converter.new $log.debug 'the engine has started' run_mode end |
#stop_running ⇒ Object
Request the engine to stop running.
168 169 170 |
# File 'lib/gloo/app/engine.rb', line 168 def stop_running @running = false end |