gloo 1.4.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/.gitignore +1 -0
- data/gloo.gemspec +0 -2
- data/lib/VERSION +1 -1
- data/lib/dependencies.rb +4 -4
- data/lib/gloo/app/args.rb +112 -0
- data/lib/gloo/app/engine.rb +247 -0
- data/lib/gloo/app/engine_context.rb +25 -0
- data/lib/gloo/app/info.rb +20 -3
- data/lib/gloo/app/log.rb +73 -1
- data/lib/gloo/app/mode.rb +27 -0
- data/lib/gloo/app/platform.rb +8 -1
- data/lib/gloo/app/settings.rb +202 -0
- data/lib/gloo/convert/converter.rb +42 -0
- data/lib/gloo/convert/string_to_date.rb +21 -0
- data/lib/gloo/convert/string_to_datetime.rb +21 -0
- data/lib/gloo/convert/string_to_decimal.rb +20 -0
- data/lib/gloo/convert/string_to_integer.rb +20 -0
- data/lib/gloo/convert/string_to_time.rb +21 -0
- data/lib/gloo/core/baseo.rb +31 -0
- data/lib/gloo/core/dictionary.rb +245 -0
- data/lib/gloo/core/error.rb +61 -0
- data/lib/gloo/core/event_manager.rb +45 -0
- data/lib/gloo/core/factory.rb +211 -0
- data/lib/gloo/core/gloo_system.rb +267 -0
- data/lib/gloo/core/heap.rb +53 -0
- data/lib/gloo/core/here.rb +36 -0
- data/lib/gloo/core/it.rb +36 -0
- data/lib/gloo/core/literal.rb +30 -0
- data/lib/gloo/core/obj.rb +318 -0
- data/lib/gloo/core/obj_finder.rb +30 -0
- data/lib/gloo/core/op.rb +40 -0
- data/lib/gloo/core/parser.rb +60 -0
- data/lib/gloo/core/pn.rb +212 -0
- data/lib/gloo/core/tokens.rb +165 -0
- data/lib/gloo/core/verb.rb +87 -0
- data/lib/gloo/exec/action.rb +48 -0
- data/lib/gloo/exec/dispatch.rb +40 -0
- data/lib/gloo/exec/exec_env.rb +75 -0
- data/lib/gloo/exec/runner.rb +45 -0
- data/lib/gloo/exec/script.rb +50 -0
- data/lib/gloo/exec/stack.rb +79 -0
- data/lib/gloo/expr/expression.rb +119 -0
- data/lib/gloo/expr/l_boolean.rb +36 -0
- data/lib/gloo/expr/l_decimal.rb +39 -0
- data/lib/gloo/expr/l_integer.rb +37 -0
- data/lib/gloo/expr/l_string.rb +58 -0
- data/lib/gloo/expr/op_div.rb +22 -0
- data/lib/gloo/expr/op_minus.rb +22 -0
- data/lib/gloo/expr/op_mult.rb +22 -0
- data/lib/gloo/expr/op_plus.rb +24 -0
- data/lib/gloo/objs/basic/alias.rb +78 -0
- data/lib/gloo/objs/basic/boolean.rb +120 -0
- data/lib/gloo/objs/basic/container.rb +65 -0
- data/lib/gloo/objs/basic/decimal.rb +76 -0
- data/lib/gloo/objs/basic/integer.rb +73 -0
- data/lib/gloo/objs/basic/script.rb +99 -0
- data/lib/gloo/objs/basic/string.rb +77 -0
- data/lib/gloo/objs/basic/text.rb +79 -0
- data/lib/gloo/objs/basic/untyped.rb +41 -0
- data/lib/gloo/objs/cli/banner.rb +1 -1
- data/lib/gloo/objs/cli/bar.rb +3 -3
- data/lib/gloo/objs/cli/colorize.rb +1 -1
- data/lib/gloo/objs/cli/confirm.rb +1 -1
- data/lib/gloo/objs/cli/menu.rb +6 -6
- data/lib/gloo/objs/cli/menu_item.rb +1 -1
- data/lib/gloo/objs/cli/pastel.rb +1 -1
- data/lib/gloo/objs/cli/prompt.rb +1 -1
- data/lib/gloo/objs/cli/select.rb +2 -2
- data/lib/gloo/objs/ctrl/each.rb +279 -0
- data/lib/gloo/objs/ctrl/repeat.rb +108 -0
- data/lib/gloo/objs/data/markdown.rb +79 -0
- data/lib/gloo/objs/data/mysql.rb +5 -5
- data/lib/gloo/objs/data/query.rb +4 -4
- data/lib/gloo/objs/data/sqlite.rb +1 -1
- data/lib/gloo/objs/data/table.rb +112 -0
- data/lib/gloo/objs/dev/git.rb +2 -2
- data/lib/gloo/objs/dev/stats.rb +4 -4
- data/lib/gloo/objs/dt/date.rb +65 -0
- data/lib/gloo/objs/dt/datetime.rb +120 -0
- data/lib/gloo/objs/dt/dt_tools.rb +100 -0
- data/lib/gloo/objs/dt/time.rb +65 -0
- data/lib/gloo/objs/ror/erb.rb +116 -0
- data/lib/gloo/objs/ror/eval.rb +107 -0
- data/lib/gloo/objs/snd/play.rb +1 -1
- data/lib/gloo/objs/snd/say.rb +1 -1
- data/lib/gloo/objs/system/file_handle.rb +4 -4
- data/lib/gloo/objs/system/ssh_exec.rb +1 -1
- data/lib/gloo/objs/system/system.rb +1 -1
- data/lib/gloo/objs/web/http_get.rb +159 -0
- data/lib/gloo/objs/web/http_post.rb +183 -0
- data/lib/gloo/objs/web/json.rb +135 -0
- data/lib/gloo/objs/web/slack.rb +130 -0
- data/lib/gloo/objs/web/teams.rb +117 -0
- data/lib/gloo/objs/web/uri.rb +148 -0
- data/lib/gloo/persist/disc_mech.rb +87 -0
- data/lib/gloo/persist/file_loader.rb +193 -0
- data/lib/gloo/persist/file_saver.rb +51 -0
- data/lib/gloo/persist/file_storage.rb +46 -0
- data/lib/gloo/persist/line_splitter.rb +81 -0
- data/lib/gloo/persist/persist_man.rb +153 -0
- data/lib/gloo/utils/format.rb +21 -0
- data/lib/gloo/utils/stats.rb +206 -0
- data/lib/gloo/utils/words.rb +19 -0
- data/lib/gloo/verbs/alert.rb +2 -2
- data/lib/gloo/verbs/beep.rb +1 -1
- data/lib/gloo/verbs/cls.rb +1 -1
- data/lib/gloo/verbs/context.rb +62 -0
- data/lib/gloo/verbs/create.rb +68 -0
- data/lib/gloo/verbs/execute.rb +56 -0
- data/lib/gloo/verbs/files.rb +49 -0
- data/lib/gloo/verbs/help.rb +1 -1
- data/lib/gloo/verbs/if.rb +92 -0
- data/lib/gloo/verbs/list.rb +98 -0
- data/lib/gloo/verbs/load.rb +45 -0
- data/lib/gloo/verbs/move.rb +89 -0
- data/lib/gloo/verbs/put.rb +94 -0
- data/lib/gloo/verbs/quit.rb +40 -0
- data/lib/gloo/verbs/reload.rb +43 -0
- data/lib/gloo/verbs/run.rb +75 -0
- data/lib/gloo/verbs/save.rb +39 -0
- data/lib/gloo/verbs/show.rb +63 -0
- data/lib/gloo/verbs/tell.rb +80 -0
- data/lib/gloo/verbs/unless.rb +92 -0
- data/lib/gloo/verbs/unload.rb +46 -0
- data/lib/gloo/verbs/version.rb +3 -3
- data/lib/gloo/verbs/wait.rb +42 -0
- data/lib/gloo.rb +2 -2
- data/lib/run.rb +2 -2
- metadata +97 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b19e54f7dd61af964351d823b146fdd04506784a31c6a146461cd608f34c879
|
4
|
+
data.tar.gz: 6d5cbb60e6de73b127a1156bcbd37a1711c3d39ae5da76c280d4893f327e65da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc2f6254760735dd87fa7d42aa8c9698d6a162afc322478e76b49cab1b52305a3d833fc85c202169f5b7e1df69ba567eaeb85fda4174e7daff451296ec1a4661
|
7
|
+
data.tar.gz: 63a96da42cd2d21cc5e27489c7161c20e3a58e1b3b72534766bf4d48c6ac469e7168b7de975e7731bd566b3698566890b568e99441899b0061b61c45fde2c2a5
|
data/.DS_Store
CHANGED
Binary file
|
data/.gitignore
CHANGED
data/gloo.gemspec
CHANGED
@@ -37,8 +37,6 @@ Gem::Specification.new do |spec|
|
|
37
37
|
# spec.add_development_dependency 'rake', '~> 10.0'
|
38
38
|
spec.add_development_dependency "rake", '~> 13.0', '>= 13.0.1'
|
39
39
|
|
40
|
-
spec.add_dependency "gloo-lang", '~> 1.2', ">= 1.4.3"
|
41
|
-
|
42
40
|
spec.add_dependency "activesupport", '~> 6.1', ">= 6.1.5"
|
43
41
|
# spec.add_dependency "activesupport", '~> 6.1', ">= 6.1.4.6"
|
44
42
|
# spec.add_dependency "activesupport", '~> 5.2', ">= 5.2.4.3"
|
data/lib/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.0.0
|
data/lib/dependencies.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
# Script to build a list of dependencies
|
3
3
|
#
|
4
4
|
|
5
|
-
require 'gloo_lang/core/baseo'
|
6
|
-
require 'gloo_lang/core/obj'
|
5
|
+
# require 'gloo_lang/core/baseo'
|
6
|
+
# require 'gloo_lang/core/obj'
|
7
7
|
|
8
8
|
path = File.dirname( File.absolute_path( __FILE__ ) )
|
9
9
|
|
@@ -11,8 +11,8 @@ files = []
|
|
11
11
|
#
|
12
12
|
# We want to start with these to avoid dependency errors later on.
|
13
13
|
#
|
14
|
-
|
15
|
-
|
14
|
+
files << File.join( path, 'gloo', 'core', 'baseo.rb' )
|
15
|
+
files << File.join( path, 'gloo', 'core', 'obj.rb' )
|
16
16
|
|
17
17
|
root = File.join( path, 'gloo', '**/*.rb' )
|
18
18
|
Dir.glob( root ).each do |ruby_file|
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# Arguments (parameters) used to specify functionality.
|
5
|
+
# These might have come from the CLI or as parameters
|
6
|
+
# in the constructor.
|
7
|
+
#
|
8
|
+
require 'active_support'
|
9
|
+
|
10
|
+
module Gloo
|
11
|
+
module App
|
12
|
+
class Args
|
13
|
+
|
14
|
+
QUIET = 'quiet'.freeze
|
15
|
+
GLOO_ENV = 'GLOO_ENV'.freeze
|
16
|
+
|
17
|
+
attr_reader :switches, :files
|
18
|
+
|
19
|
+
#
|
20
|
+
# Create arguments and setup.
|
21
|
+
#
|
22
|
+
def initialize( engine, params = [] )
|
23
|
+
@engine = engine
|
24
|
+
@switches = []
|
25
|
+
@files = []
|
26
|
+
|
27
|
+
params.each { |o| process_one_arg( o ) }
|
28
|
+
ARGV.each { |o| process_one_arg( o ) }
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Was the --quiet arg passed?
|
33
|
+
#
|
34
|
+
def quiet?
|
35
|
+
return @switches.include?( QUIET )
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Is the version switch set?
|
40
|
+
#
|
41
|
+
def version?
|
42
|
+
@switches.include?( Gloo::App::Mode::VERSION.to_s )
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Is the help switch set?
|
47
|
+
#
|
48
|
+
def help?
|
49
|
+
@switches.include?( Gloo::App::Mode::HELP.to_s )
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# Is the cli switch set?
|
54
|
+
#
|
55
|
+
def cli?
|
56
|
+
@switches.include?( Gloo::App::Mode::CLI.to_s )
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# Is the embed switch set?
|
61
|
+
#
|
62
|
+
def embed?
|
63
|
+
@switches.include?( Gloo::App::Mode::EMBED.to_s )
|
64
|
+
end
|
65
|
+
|
66
|
+
#
|
67
|
+
# Detect the mode to be run in.
|
68
|
+
# Start by seeing if a mode is specified.
|
69
|
+
# Then look for the presence of files.
|
70
|
+
# Then finally use the default: embedded mode.
|
71
|
+
#
|
72
|
+
def detect_mode
|
73
|
+
mode = if ENV[ GLOO_ENV ] == Gloo::App::Mode::TEST.to_s
|
74
|
+
Mode::TEST
|
75
|
+
elsif version?
|
76
|
+
Mode::VERSION
|
77
|
+
elsif help?
|
78
|
+
Mode::HELP
|
79
|
+
elsif cli?
|
80
|
+
Mode::CLI
|
81
|
+
elsif embed?
|
82
|
+
Mode::EMBED
|
83
|
+
elsif @files.count.positive?
|
84
|
+
Mode::SCRIPT
|
85
|
+
else
|
86
|
+
Mode.default_mode
|
87
|
+
end
|
88
|
+
@engine.log.debug "running in #{mode} mode"
|
89
|
+
|
90
|
+
return mode
|
91
|
+
end
|
92
|
+
|
93
|
+
# ---------------------------------------------------------------------
|
94
|
+
# Private
|
95
|
+
# ---------------------------------------------------------------------
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
#
|
100
|
+
# Process one argument or parameter.
|
101
|
+
#
|
102
|
+
def process_one_arg( arg )
|
103
|
+
if arg.start_with? '--'
|
104
|
+
switches << arg[ 2..-1 ]
|
105
|
+
else
|
106
|
+
files << arg
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,247 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# The Gloo Script Engine.
|
5
|
+
# The Engine aggregates all the elements needed to run gloo.
|
6
|
+
# The Engine runs the main event loop and delegates processing
|
7
|
+
# to the relevant element.
|
8
|
+
#
|
9
|
+
|
10
|
+
module Gloo
|
11
|
+
module App
|
12
|
+
class Engine
|
13
|
+
|
14
|
+
attr_reader :settings, :log
|
15
|
+
attr_reader :args, :mode, :running, :platform,
|
16
|
+
:dictionary, :parser, :heap, :factory
|
17
|
+
attr_accessor :last_cmd, :persist_man, :event_manager,
|
18
|
+
:exec_env, :converter
|
19
|
+
|
20
|
+
#
|
21
|
+
# Set up the engine with basic elements.
|
22
|
+
#
|
23
|
+
def initialize( context )
|
24
|
+
@args = Args.new( self, context.params )
|
25
|
+
@settings = Settings.new( self, context.user_root )
|
26
|
+
|
27
|
+
@log = context.log.new( self, @args.quiet? )
|
28
|
+
@log.debug "log (class: #{@log.class.name}) in use ..."
|
29
|
+
|
30
|
+
@platform = context.platform
|
31
|
+
@log.debug "platform (class: #{@platform.class.name}) in use ..."
|
32
|
+
|
33
|
+
@log.debug 'engine intialized...'
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# Start the engine.
|
38
|
+
# Load object and verb definitions and setup engine elements.
|
39
|
+
#
|
40
|
+
def start
|
41
|
+
@log.debug 'starting the engine...'
|
42
|
+
@log.debug Gloo::App::Info.display_title
|
43
|
+
@mode = @args.detect_mode
|
44
|
+
@running = true
|
45
|
+
|
46
|
+
@dictionary = Gloo::Core::Dictionary.get
|
47
|
+
|
48
|
+
@parser = Gloo::Core::Parser.new( self )
|
49
|
+
@heap = Gloo::Core::Heap.new( self )
|
50
|
+
@factory = Gloo::Core::Factory.new( self )
|
51
|
+
@persist_man = Gloo::Persist::PersistMan.new( self )
|
52
|
+
@event_manager = Gloo::Core::EventManager.new( self )
|
53
|
+
|
54
|
+
@exec_env = Gloo::Exec::ExecEnv.new( self )
|
55
|
+
@converter = Gloo::Convert::Converter.new( self )
|
56
|
+
|
57
|
+
@log.debug 'the engine has started'
|
58
|
+
run_mode
|
59
|
+
end
|
60
|
+
|
61
|
+
# ---------------------------------------------------------------------
|
62
|
+
# Serialization
|
63
|
+
# ---------------------------------------------------------------------
|
64
|
+
|
65
|
+
#
|
66
|
+
# Prepare for serialization by removing any file references.
|
67
|
+
# Without this, the engine cannot be serialized.
|
68
|
+
#
|
69
|
+
def prep_serialize
|
70
|
+
@log.prep_serialize
|
71
|
+
end
|
72
|
+
|
73
|
+
#
|
74
|
+
# Get the serialized version of this Engine.
|
75
|
+
#
|
76
|
+
def serialize
|
77
|
+
prep_serialize
|
78
|
+
Marshal::dump( self )
|
79
|
+
end
|
80
|
+
|
81
|
+
#
|
82
|
+
# Deserialize the Engine data.
|
83
|
+
#
|
84
|
+
def self.deserialize data
|
85
|
+
e = Marshal::load( data )
|
86
|
+
e.restore_after_deserialization
|
87
|
+
return e
|
88
|
+
end
|
89
|
+
|
90
|
+
#
|
91
|
+
# Restore the engine after deserialization.
|
92
|
+
#
|
93
|
+
def restore_after_deserialization
|
94
|
+
@log.restore_after_deserialization
|
95
|
+
end
|
96
|
+
|
97
|
+
# ---------------------------------------------------------------------
|
98
|
+
# Run
|
99
|
+
# ---------------------------------------------------------------------
|
100
|
+
|
101
|
+
#
|
102
|
+
# Run gloo in the selected mode.
|
103
|
+
#
|
104
|
+
def run_mode
|
105
|
+
@log.debug "running gloo in #{@mode} mode"
|
106
|
+
|
107
|
+
if @mode == Mode::VERSION
|
108
|
+
run_version
|
109
|
+
elsif @mode == Mode::SCRIPT
|
110
|
+
run_files
|
111
|
+
elsif @mode == Mode::EMBED
|
112
|
+
run_keep_alive
|
113
|
+
else
|
114
|
+
run
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
#
|
119
|
+
# Run files specified on the CLI.
|
120
|
+
# Then quit.
|
121
|
+
#
|
122
|
+
def run_files
|
123
|
+
load_files
|
124
|
+
quit
|
125
|
+
end
|
126
|
+
|
127
|
+
#
|
128
|
+
# Load all file specified in the CLI.
|
129
|
+
#
|
130
|
+
def load_files
|
131
|
+
@args.files.each { |f| @persist_man.load( f ) }
|
132
|
+
end
|
133
|
+
|
134
|
+
#
|
135
|
+
# Run in interactive mode.
|
136
|
+
#
|
137
|
+
def run
|
138
|
+
# Open default file(s)
|
139
|
+
self.open_start_file
|
140
|
+
|
141
|
+
# Open any files specifed in args
|
142
|
+
load_files
|
143
|
+
|
144
|
+
unless @mode == Mode::SCRIPT || @args.quiet?
|
145
|
+
self.loop
|
146
|
+
end
|
147
|
+
|
148
|
+
quit
|
149
|
+
end
|
150
|
+
|
151
|
+
#
|
152
|
+
# Run in Embedded mode, which means we'll
|
153
|
+
# start the engine, but wait for external inputs.
|
154
|
+
#
|
155
|
+
def run_keep_alive
|
156
|
+
@log.debug 'Running in Embedded mode...'
|
157
|
+
end
|
158
|
+
|
159
|
+
#
|
160
|
+
# Get the setting for the start_with file and open it.
|
161
|
+
#
|
162
|
+
def open_start_file
|
163
|
+
name = @settings.start_with
|
164
|
+
@persist_man.load( name ) if name
|
165
|
+
end
|
166
|
+
|
167
|
+
#
|
168
|
+
# Is the last command entered blank?
|
169
|
+
#
|
170
|
+
def last_cmd_blank?
|
171
|
+
return true if @last_cmd.nil?
|
172
|
+
return true if @last_cmd.strip.empty?
|
173
|
+
|
174
|
+
return false
|
175
|
+
end
|
176
|
+
|
177
|
+
#
|
178
|
+
# Prompt, Get input, process.
|
179
|
+
#
|
180
|
+
def loop
|
181
|
+
while @running
|
182
|
+
@last_cmd = @platform.prompt_cmd
|
183
|
+
process_cmd
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
#
|
188
|
+
# Process the command.
|
189
|
+
#
|
190
|
+
def process_cmd
|
191
|
+
if last_cmd_blank?
|
192
|
+
@platform.clear_screen
|
193
|
+
return
|
194
|
+
end
|
195
|
+
|
196
|
+
@parser.run @last_cmd
|
197
|
+
end
|
198
|
+
|
199
|
+
#
|
200
|
+
# Request the engine to stop running.
|
201
|
+
#
|
202
|
+
def stop_running
|
203
|
+
@running = false
|
204
|
+
end
|
205
|
+
|
206
|
+
#
|
207
|
+
# Do any clean up and quit.
|
208
|
+
#
|
209
|
+
def quit
|
210
|
+
@log.debug 'quitting...'
|
211
|
+
end
|
212
|
+
|
213
|
+
# ---------------------------------------------------------------------
|
214
|
+
# Helpers
|
215
|
+
# ---------------------------------------------------------------------
|
216
|
+
|
217
|
+
#
|
218
|
+
# Show the version information and then quit.
|
219
|
+
#
|
220
|
+
def run_version
|
221
|
+
@platform.show Info.full_version unless @args.quiet?
|
222
|
+
quit
|
223
|
+
end
|
224
|
+
|
225
|
+
# ---------------------------------------------------------------------
|
226
|
+
# Error Handling
|
227
|
+
# ---------------------------------------------------------------------
|
228
|
+
|
229
|
+
#
|
230
|
+
# Did the last command result in an error?
|
231
|
+
#
|
232
|
+
def error?
|
233
|
+
return !@heap.error.value.nil?
|
234
|
+
end
|
235
|
+
|
236
|
+
#
|
237
|
+
# Report an error.
|
238
|
+
# Write it to the log and set the heap error value.
|
239
|
+
#
|
240
|
+
def err( msg )
|
241
|
+
@log.error msg
|
242
|
+
@heap.error.set_to msg
|
243
|
+
end
|
244
|
+
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2022 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# The context (parameters) for the Gloo Script Engine.
|
5
|
+
#
|
6
|
+
|
7
|
+
module Gloo
|
8
|
+
module App
|
9
|
+
class EngineContext
|
10
|
+
|
11
|
+
attr_accessor :params, :platform, :log, :user_root
|
12
|
+
|
13
|
+
#
|
14
|
+
# Create the context, supplying defaults where relevant.
|
15
|
+
#
|
16
|
+
def initialize( params = [], platform=nil, log=nil, user_root=nil )
|
17
|
+
@params = params
|
18
|
+
@platform = platform ? platform : Gloo::App::Platform.new
|
19
|
+
@log = log ? log : Gloo::App::Log
|
20
|
+
@user_root = user_root
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/gloo/app/info.rb
CHANGED
@@ -4,11 +4,11 @@
|
|
4
4
|
# Application information such as Version and public name.
|
5
5
|
#
|
6
6
|
|
7
|
-
require 'gloo-lang'
|
7
|
+
# require 'gloo-lang'
|
8
8
|
|
9
9
|
module Gloo
|
10
10
|
module App
|
11
|
-
class Info
|
11
|
+
class Info
|
12
12
|
|
13
13
|
#
|
14
14
|
# Load the version from the VERSION file.
|
@@ -30,6 +30,23 @@ module Gloo
|
|
30
30
|
return "#{APP_NAME}, version #{VERSION}"
|
31
31
|
end
|
32
32
|
|
33
|
+
|
34
|
+
#
|
35
|
+
# Get the full application version information,
|
36
|
+
# including engine version.
|
37
|
+
#
|
38
|
+
def self.full_version
|
39
|
+
return "#{display_title}\n#{ruby_info}"
|
40
|
+
return str
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Get the version of Ruby.
|
45
|
+
#
|
46
|
+
def self.ruby_info
|
47
|
+
return "Ruby version: #{RUBY_VERSION}"
|
48
|
+
end
|
49
|
+
|
33
50
|
end
|
34
51
|
end
|
35
|
-
end
|
52
|
+
end
|
data/lib/gloo/app/log.rb
CHANGED
@@ -9,7 +9,60 @@ require 'colorized_string'
|
|
9
9
|
|
10
10
|
module Gloo
|
11
11
|
module App
|
12
|
-
class Log
|
12
|
+
class Log
|
13
|
+
|
14
|
+
attr_accessor :quiet
|
15
|
+
attr_reader :logger
|
16
|
+
|
17
|
+
# ---------------------------------------------------------------------
|
18
|
+
# Initialization
|
19
|
+
# ---------------------------------------------------------------------
|
20
|
+
|
21
|
+
#
|
22
|
+
# Set up a logger.
|
23
|
+
# If quiet is true, then message are written to the log
|
24
|
+
# but not to the console.
|
25
|
+
#
|
26
|
+
def initialize( engine, quiet=true )
|
27
|
+
@engine = engine
|
28
|
+
@quite = quiet
|
29
|
+
|
30
|
+
create_logger
|
31
|
+
|
32
|
+
debug 'log intialized...'
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Create the default [file] logger.
|
37
|
+
#
|
38
|
+
def create_logger
|
39
|
+
f = File.join( @engine.settings.log_path, 'gloo.log' )
|
40
|
+
@logger = Logger.new( f )
|
41
|
+
@logger.level = Logger::DEBUG
|
42
|
+
end
|
43
|
+
|
44
|
+
# ---------------------------------------------------------------------
|
45
|
+
# Standard Output
|
46
|
+
# ---------------------------------------------------------------------
|
47
|
+
|
48
|
+
#
|
49
|
+
# Show a message unless we're in quite mode.
|
50
|
+
#
|
51
|
+
def show( msg )
|
52
|
+
puts msg unless @quiet
|
53
|
+
end
|
54
|
+
|
55
|
+
# ---------------------------------------------------------------------
|
56
|
+
# Logging functions
|
57
|
+
# ---------------------------------------------------------------------
|
58
|
+
|
59
|
+
#
|
60
|
+
# Write a debug message to the log.
|
61
|
+
#
|
62
|
+
def debug( msg )
|
63
|
+
@logger.debug msg
|
64
|
+
end
|
65
|
+
|
13
66
|
|
14
67
|
#
|
15
68
|
# Write an information message to the log.
|
@@ -48,6 +101,25 @@ module Gloo
|
|
48
101
|
end
|
49
102
|
end
|
50
103
|
|
104
|
+
# ---------------------------------------------------------------------
|
105
|
+
# Serialization
|
106
|
+
# ---------------------------------------------------------------------
|
107
|
+
|
108
|
+
#
|
109
|
+
# Prepare for serialization by removing the file reference.
|
110
|
+
# Without this, the engine cannot be serialized.
|
111
|
+
#
|
112
|
+
def prep_serialize
|
113
|
+
@logger = nil
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# Restore the logger after deserialization.
|
118
|
+
#
|
119
|
+
def restore_after_deserialization
|
120
|
+
create_logger
|
121
|
+
end
|
122
|
+
|
51
123
|
end
|
52
124
|
end
|
53
125
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# Mode the Application is running in.
|
5
|
+
#
|
6
|
+
|
7
|
+
module Gloo
|
8
|
+
module App
|
9
|
+
class Mode
|
10
|
+
|
11
|
+
EMBED = :embed # Run as embedded script processor
|
12
|
+
CLI = :cli # Run in interactive (CLI) mode
|
13
|
+
SCRIPT = :script # Run a script
|
14
|
+
VERSION = :version # Show version information
|
15
|
+
HELP = :help # Show the help screen
|
16
|
+
TEST = :test # Running in Unit Test mode.
|
17
|
+
|
18
|
+
#
|
19
|
+
# Get the default mode.
|
20
|
+
#
|
21
|
+
def self.default_mode
|
22
|
+
return EMBED
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/gloo/app/platform.rb
CHANGED
@@ -17,7 +17,7 @@ require 'pastel'
|
|
17
17
|
|
18
18
|
module Gloo
|
19
19
|
module App
|
20
|
-
class Platform
|
20
|
+
class Platform
|
21
21
|
|
22
22
|
DEFAULT_TMP_FILE = 'tmp.txt'.freeze
|
23
23
|
|
@@ -73,6 +73,13 @@ module Gloo
|
|
73
73
|
return File.read( tmp )
|
74
74
|
end
|
75
75
|
|
76
|
+
#
|
77
|
+
# Get the file mechanism for this platform.
|
78
|
+
#
|
79
|
+
def getFileMech( engine )
|
80
|
+
return Gloo::Persist::DiscMech.new( engine )
|
81
|
+
end
|
82
|
+
|
76
83
|
# ---------------------------------------------------------------------
|
77
84
|
# Color helper
|
78
85
|
# ---------------------------------------------------------------------
|