Class: GlooLang::App::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/gloo_lang/app/engine.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_lang/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

#argsObject (readonly)

Returns the value of attribute args.



15
16
17
# File 'lib/gloo_lang/app/engine.rb', line 15

def args
  @args
end

#converterObject

Returns the value of attribute converter.



17
18
19
# File 'lib/gloo_lang/app/engine.rb', line 17

def converter
  @converter
end

#dictionaryObject (readonly)

Returns the value of attribute dictionary.



15
16
17
# File 'lib/gloo_lang/app/engine.rb', line 15

def dictionary
  @dictionary
end

#event_managerObject

Returns the value of attribute event_manager.



17
18
19
# File 'lib/gloo_lang/app/engine.rb', line 17

def event_manager
  @event_manager
end

#exec_envObject

Returns the value of attribute exec_env.



17
18
19
# File 'lib/gloo_lang/app/engine.rb', line 17

def exec_env
  @exec_env
end

#factoryObject (readonly)

Returns the value of attribute factory.



15
16
17
# File 'lib/gloo_lang/app/engine.rb', line 15

def factory
  @factory
end

#heapObject (readonly)

Returns the value of attribute heap.



15
16
17
# File 'lib/gloo_lang/app/engine.rb', line 15

def heap
  @heap
end

#last_cmdObject

Returns the value of attribute last_cmd.



17
18
19
# File 'lib/gloo_lang/app/engine.rb', line 17

def last_cmd
  @last_cmd
end

#logObject (readonly)

Returns the value of attribute log.



14
15
16
# File 'lib/gloo_lang/app/engine.rb', line 14

def log
  @log
end

#modeObject (readonly)

Returns the value of attribute mode.



15
16
17
# File 'lib/gloo_lang/app/engine.rb', line 15

def mode
  @mode
end

#parserObject (readonly)

Returns the value of attribute parser.



15
16
17
# File 'lib/gloo_lang/app/engine.rb', line 15

def parser
  @parser
end

#persist_manObject

Returns the value of attribute persist_man.



17
18
19
# File 'lib/gloo_lang/app/engine.rb', line 17

def persist_man
  @persist_man
end

#platformObject (readonly)

Returns the value of attribute platform.



15
16
17
# File 'lib/gloo_lang/app/engine.rb', line 15

def platform
  @platform
end

#runningObject (readonly)

Returns the value of attribute running.



15
16
17
# File 'lib/gloo_lang/app/engine.rb', line 15

def running
  @running
end

#settingsObject (readonly)

Returns the value of attribute settings.



14
15
16
# File 'lib/gloo_lang/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_lang/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_lang/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?

Returns:

  • (Boolean)


232
233
234
# File 'lib/gloo_lang/app/engine.rb', line 232

def error?
  return !@heap.error.value.nil?
end

#last_cmd_blank?Boolean

Is the last command entered blank?

Returns:

  • (Boolean)


170
171
172
173
174
175
# File 'lib/gloo_lang/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_filesObject

Load all file specified in the CLI.



130
131
132
# File 'lib/gloo_lang/app/engine.rb', line 130

def load_files
  @args.files.each { |f| @persist_man.load( f ) }
end

#loopObject

Prompt, Get input, process.



180
181
182
183
184
185
# File 'lib/gloo_lang/app/engine.rb', line 180

def loop
  while @running
    @last_cmd = @platform.prompt_cmd
    process_cmd
  end
end

#open_start_fileObject

Get the setting for the start_with file and open it.



162
163
164
165
# File 'lib/gloo_lang/app/engine.rb', line 162

def open_start_file
  name = @settings.start_with
  @persist_man.load( name ) if name
end

#prep_serializeObject

Prepare for serialization by removing any file references. Without this, the engine cannot be serialized.



69
70
71
# File 'lib/gloo_lang/app/engine.rb', line 69

def prep_serialize
  @log.prep_serialize
end

#process_cmdObject

Process the command.



190
191
192
193
194
195
196
197
# File 'lib/gloo_lang/app/engine.rb', line 190

def process_cmd
  if last_cmd_blank?
    @platform.clear_screen
    return
  end

  @parser.run @last_cmd
end

#quitObject

Do any clean up and quit.



209
210
211
# File 'lib/gloo_lang/app/engine.rb', line 209

def quit
  @log.debug 'quitting...'
end

#restore_after_deserializationObject

Restore the engine after deserialization.



93
94
95
# File 'lib/gloo_lang/app/engine.rb', line 93

def restore_after_deserialization
  @log.restore_after_deserialization
end

#runObject

Run in interactive mode.



137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/gloo_lang/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_filesObject

Run files specified on the CLI. Then quit.



122
123
124
125
# File 'lib/gloo_lang/app/engine.rb', line 122

def run_files
  load_files
  quit
end

#run_keep_aliveObject

Run in Embedded mode, which means we’ll start the engine, but wait for external inputs.



155
156
157
# File 'lib/gloo_lang/app/engine.rb', line 155

def run_keep_alive
  @log.debug 'Running in Embedded mode...'
end

#run_modeObject

Run gloo in the selected mode.



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/gloo_lang/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_versionObject

Show the version information and then quit.



220
221
222
223
# File 'lib/gloo_lang/app/engine.rb', line 220

def run_version
  @platform.show Info.full_version unless @args.quiet?
  quit
end

#serializeObject

Get the serialized version of this Engine.



76
77
78
79
# File 'lib/gloo_lang/app/engine.rb', line 76

def serialize
  prep_serialize
  Marshal::dump( self )
end

#startObject

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_lang/app/engine.rb', line 40

def start
  @log.debug 'starting the engine...'
  @log.debug Info.display_title
  @mode = @args.detect_mode
  @running = true

  @dictionary = GlooLang::Core::Dictionary.get

  @parser = GlooLang::Core::Parser.new( self )
  @heap = GlooLang::Core::Heap.new( self )
  @factory = GlooLang::Core::Factory.new( self )
  @persist_man = GlooLang::Persist::PersistMan.new( self )
  @event_manager = GlooLang::Core::EventManager.new( self )

  @exec_env = GlooLang::Exec::ExecEnv.new( self )
  @converter = GlooLang::Convert::Converter.new( self )

  @log.debug 'the engine has started'
  run_mode
end

#stop_runningObject

Request the engine to stop running.



202
203
204
# File 'lib/gloo_lang/app/engine.rb', line 202

def stop_running
  @running = false
end