gloo-lang 0.9.2 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/gloo-lang.gemspec +1 -0
- data/lib/VERSION +1 -1
- data/lib/dependencies.rb +2 -2
- data/lib/gloo-lang.rb +1 -5
- data/lib/gloo_lang/app/args.rb +111 -0
- data/lib/gloo_lang/app/engine.rb +200 -0
- data/lib/gloo_lang/app/help.rb +117 -0
- data/lib/gloo_lang/app/info.rb +34 -0
- data/lib/gloo_lang/app/log.rb +81 -0
- data/lib/gloo_lang/app/mode.rb +27 -0
- data/lib/gloo_lang/app/platform.rb +75 -0
- data/lib/gloo_lang/app/settings.rb +185 -0
- data/lib/gloo_lang/convert/converter.rb +35 -0
- data/lib/gloo_lang/convert/string_to_datetime.rb +21 -0
- data/lib/gloo_lang/convert/string_to_decimal.rb +20 -0
- data/lib/gloo_lang/convert/string_to_integer.rb +20 -0
- data/lib/gloo_lang/core/baseo.rb +30 -0
- data/lib/gloo_lang/core/dictionary.rb +181 -0
- data/lib/gloo_lang/core/error.rb +61 -0
- data/lib/gloo_lang/core/event_manager.rb +44 -0
- data/lib/gloo_lang/core/factory.rb +210 -0
- data/lib/gloo_lang/core/gloo_system.rb +266 -0
- data/lib/gloo_lang/core/heap.rb +52 -0
- data/lib/gloo_lang/core/here.rb +36 -0
- data/lib/gloo_lang/core/it.rb +36 -0
- data/lib/gloo_lang/core/literal.rb +30 -0
- data/lib/gloo_lang/core/obj.rb +303 -0
- data/lib/gloo_lang/core/obj_finder.rb +30 -0
- data/lib/gloo_lang/core/op.rb +40 -0
- data/lib/gloo_lang/core/parser.rb +59 -0
- data/lib/gloo_lang/core/pn.rb +188 -0
- data/lib/gloo_lang/core/tokens.rb +165 -0
- data/lib/gloo_lang/core/verb.rb +86 -0
- data/lib/gloo_lang/exec/action.rb +48 -0
- data/lib/gloo_lang/exec/dispatch.rb +40 -0
- data/lib/gloo_lang/exec/exec_env.rb +74 -0
- data/lib/gloo_lang/exec/runner.rb +45 -0
- data/lib/gloo_lang/exec/script.rb +49 -0
- data/lib/gloo_lang/exec/stack.rb +78 -0
- data/lib/gloo_lang/expr/expression.rb +118 -0
- data/lib/gloo_lang/expr/l_boolean.rb +36 -0
- data/lib/gloo_lang/expr/l_decimal.rb +39 -0
- data/lib/gloo_lang/expr/l_integer.rb +37 -0
- data/lib/gloo_lang/expr/l_string.rb +58 -0
- data/lib/gloo_lang/expr/op_div.rb +22 -0
- data/lib/gloo_lang/expr/op_minus.rb +22 -0
- data/lib/gloo_lang/expr/op_mult.rb +22 -0
- data/lib/gloo_lang/expr/op_plus.rb +24 -0
- data/lib/gloo_lang/help/app/application.txt +22 -0
- data/lib/gloo_lang/help/app/configuration.txt +7 -0
- data/lib/gloo_lang/help/app/default_help.txt +14 -0
- data/lib/gloo_lang/help/app/logging.txt +16 -0
- data/lib/gloo_lang/help/core/color.txt +31 -0
- data/lib/gloo_lang/help/core/error.txt +33 -0
- data/lib/gloo_lang/help/core/events.txt +21 -0
- data/lib/gloo_lang/help/core/gloo_system.txt +57 -0
- data/lib/gloo_lang/help/core/here.txt +30 -0
- data/lib/gloo_lang/help/core/it.txt +23 -0
- data/lib/gloo_lang/help/core/ops.txt +16 -0
- data/lib/gloo_lang/help/core/pathname.txt +29 -0
- data/lib/gloo_lang/help/objs/basic/alias.txt +36 -0
- data/lib/gloo_lang/help/objs/basic/boolean.txt +28 -0
- data/lib/gloo_lang/help/objs/basic/container.txt +33 -0
- data/lib/gloo_lang/help/objs/basic/decimal.txt +28 -0
- data/lib/gloo_lang/help/objs/basic/integer.txt +27 -0
- data/lib/gloo_lang/help/objs/basic/script.txt +29 -0
- data/lib/gloo_lang/help/objs/basic/string.txt +28 -0
- data/lib/gloo_lang/help/objs/basic/text.txt +27 -0
- data/lib/gloo_lang/help/objs/basic/untyped.txt +22 -0
- data/lib/gloo_lang/help/objs/cli/banner.txt +49 -0
- data/lib/gloo_lang/help/objs/cli/bar.txt +37 -0
- data/lib/gloo_lang/help/objs/cli/colorize.txt +33 -0
- data/lib/gloo_lang/help/objs/cli/confirm.txt +26 -0
- data/lib/gloo_lang/help/objs/cli/menu.txt +44 -0
- data/lib/gloo_lang/help/objs/cli/menu_item.txt +26 -0
- data/lib/gloo_lang/help/objs/cli/pastel.txt +43 -0
- data/lib/gloo_lang/help/objs/cli/prompt.txt +27 -0
- data/lib/gloo_lang/help/objs/cli/select.txt +34 -0
- data/lib/gloo_lang/help/objs/ctrl/each.txt +48 -0
- data/lib/gloo_lang/help/objs/ctrl/repeat.txt +38 -0
- data/lib/gloo_lang/help/objs/data/markdown.txt +25 -0
- data/lib/gloo_lang/help/objs/data/mysql.txt +40 -0
- data/lib/gloo_lang/help/objs/data/query.txt +37 -0
- data/lib/gloo_lang/help/objs/data/sqlite.txt +26 -0
- data/lib/gloo_lang/help/objs/data/table.txt +46 -0
- data/lib/gloo_lang/help/objs/dev/git_repo.txt +36 -0
- data/lib/gloo_lang/help/objs/dev/stats.txt +36 -0
- data/lib/gloo_lang/help/objs/dt/date.txt +23 -0
- data/lib/gloo_lang/help/objs/dt/datetime.txt +24 -0
- data/lib/gloo_lang/help/objs/dt/time.txt +23 -0
- data/lib/gloo_lang/help/objs/ror/erb.txt +37 -0
- data/lib/gloo_lang/help/objs/ror/eval.txt +24 -0
- data/lib/gloo_lang/help/objs/snd/play.txt +23 -0
- data/lib/gloo_lang/help/objs/snd/say.txt +28 -0
- data/lib/gloo_lang/help/objs/system/file.txt +48 -0
- data/lib/gloo_lang/help/objs/system/ssh_exec.txt +30 -0
- data/lib/gloo_lang/help/objs/system/system.txt +32 -0
- data/lib/gloo_lang/help/objs/web/http_get.txt +35 -0
- data/lib/gloo_lang/help/objs/web/http_post.txt +34 -0
- data/lib/gloo_lang/help/objs/web/json.txt +34 -0
- data/lib/gloo_lang/help/objs/web/slack.txt +33 -0
- data/lib/gloo_lang/help/objs/web/teams.txt +30 -0
- data/lib/gloo_lang/help/objs/web/uri.txt +38 -0
- data/lib/gloo_lang/help/verbs/alert.txt +33 -0
- data/lib/gloo_lang/help/verbs/beep.txt +25 -0
- data/lib/gloo_lang/help/verbs/cls.txt +24 -0
- data/lib/gloo_lang/help/verbs/context.txt +43 -0
- data/lib/gloo_lang/help/verbs/create.txt +33 -0
- data/lib/gloo_lang/help/verbs/execute.txt +27 -0
- data/lib/gloo_lang/help/verbs/help.txt +34 -0
- data/lib/gloo_lang/help/verbs/if.txt +37 -0
- data/lib/gloo_lang/help/verbs/list.txt +34 -0
- data/lib/gloo_lang/help/verbs/load.txt +38 -0
- data/lib/gloo_lang/help/verbs/move.txt +42 -0
- data/lib/gloo_lang/help/verbs/put.txt +38 -0
- data/lib/gloo_lang/help/verbs/quit.txt +25 -0
- data/lib/gloo_lang/help/verbs/run.txt +41 -0
- data/lib/gloo_lang/help/verbs/save.txt +26 -0
- data/lib/gloo_lang/help/verbs/show.txt +30 -0
- data/lib/gloo_lang/help/verbs/tell.txt +34 -0
- data/lib/gloo_lang/help/verbs/unless.txt +38 -0
- data/lib/gloo_lang/help/verbs/version.txt +32 -0
- data/lib/gloo_lang/help/verbs/wait.txt +29 -0
- data/lib/gloo_lang/objs/basic/alias.rb +78 -0
- data/lib/gloo_lang/objs/basic/boolean.rb +120 -0
- data/lib/gloo_lang/objs/basic/container.rb +65 -0
- data/lib/gloo_lang/objs/basic/decimal.rb +76 -0
- data/lib/gloo_lang/objs/basic/integer.rb +73 -0
- data/lib/gloo_lang/objs/basic/script.rb +99 -0
- data/lib/gloo_lang/objs/basic/string.rb +77 -0
- data/lib/gloo_lang/objs/basic/text.rb +79 -0
- data/lib/gloo_lang/objs/basic/untyped.rb +41 -0
- data/lib/gloo_lang/objs/ctrl/each.rb +279 -0
- data/lib/gloo_lang/objs/ctrl/repeat.rb +108 -0
- data/lib/gloo_lang/objs/data/markdown.rb +79 -0
- data/lib/gloo_lang/objs/data/mysql.rb +192 -0
- data/lib/gloo_lang/objs/data/query.rb +176 -0
- data/lib/gloo_lang/objs/data/sqlite.rb +159 -0
- data/lib/gloo_lang/objs/data/table.rb +112 -0
- data/lib/gloo_lang/objs/dt/date.rb +50 -0
- data/lib/gloo_lang/objs/dt/datetime.rb +62 -0
- data/lib/gloo_lang/objs/dt/time.rb +50 -0
- data/lib/gloo_lang/objs/ror/erb.rb +116 -0
- data/lib/gloo_lang/objs/ror/eval.rb +107 -0
- data/lib/gloo_lang/objs/web/http_get.rb +159 -0
- data/lib/gloo_lang/objs/web/http_post.rb +183 -0
- data/lib/gloo_lang/objs/web/json.rb +135 -0
- data/lib/gloo_lang/objs/web/slack.rb +130 -0
- data/lib/gloo_lang/objs/web/teams.rb +117 -0
- data/lib/gloo_lang/objs/web/uri.rb +148 -0
- data/lib/gloo_lang/persist/file_loader.rb +191 -0
- data/lib/gloo_lang/persist/file_saver.rb +49 -0
- data/lib/gloo_lang/persist/file_storage.rb +45 -0
- data/lib/gloo_lang/persist/line_splitter.rb +81 -0
- data/lib/gloo_lang/persist/persist_man.rb +120 -0
- data/lib/gloo_lang/utils/format.rb +21 -0
- data/lib/gloo_lang/utils/stats.rb +205 -0
- data/lib/gloo_lang/utils/words.rb +19 -0
- data/lib/gloo_lang/verbs/context.rb +62 -0
- data/lib/gloo_lang/verbs/create.rb +68 -0
- data/lib/gloo_lang/verbs/execute.rb +56 -0
- data/lib/gloo_lang/verbs/help.rb +264 -0
- data/lib/gloo_lang/verbs/if.rb +92 -0
- data/lib/gloo_lang/verbs/list.rb +98 -0
- data/lib/gloo_lang/verbs/load.rb +45 -0
- data/lib/gloo_lang/verbs/move.rb +89 -0
- data/lib/gloo_lang/verbs/put.rb +94 -0
- data/lib/gloo_lang/verbs/quit.rb +40 -0
- data/lib/gloo_lang/verbs/run.rb +75 -0
- data/lib/gloo_lang/verbs/save.rb +39 -0
- data/lib/gloo_lang/verbs/show.rb +64 -0
- data/lib/gloo_lang/verbs/tell.rb +79 -0
- data/lib/gloo_lang/verbs/unless.rb +92 -0
- data/lib/gloo_lang/verbs/version.rb +37 -0
- data/lib/gloo_lang/verbs/wait.rb +42 -0
- metadata +192 -2
@@ -0,0 +1,279 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# A looping construct...do something for each whatever in something.
|
5
|
+
# This object has several possible uses:
|
6
|
+
# - each word in a string
|
7
|
+
# - each line in a string
|
8
|
+
# - each file in a directory
|
9
|
+
# - each git repo in a directory
|
10
|
+
#
|
11
|
+
|
12
|
+
module GlooLang
|
13
|
+
module Objs
|
14
|
+
class Each < GlooLang::Core::Obj
|
15
|
+
|
16
|
+
KEYWORD = 'each'.freeze
|
17
|
+
KEYWORD_SHORT = 'each'.freeze
|
18
|
+
CHILD = 'child'.freeze
|
19
|
+
WORD = 'word'.freeze
|
20
|
+
LINE = 'line'.freeze
|
21
|
+
FILE = 'file'.freeze
|
22
|
+
REPO = 'repo'.freeze
|
23
|
+
IN = 'IN'.freeze
|
24
|
+
DO = 'do'.freeze
|
25
|
+
|
26
|
+
#
|
27
|
+
# The name of the object type.
|
28
|
+
#
|
29
|
+
def self.typename
|
30
|
+
return KEYWORD
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# The short name of the object type.
|
35
|
+
#
|
36
|
+
def self.short_typename
|
37
|
+
return KEYWORD_SHORT
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Get the URI from the child object.
|
42
|
+
# Returns nil if there is none.
|
43
|
+
#
|
44
|
+
def in_value
|
45
|
+
o = find_child IN
|
46
|
+
return o ? o.value : nil
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# Run the do script once.
|
51
|
+
#
|
52
|
+
def run_do
|
53
|
+
o = find_child DO
|
54
|
+
return unless o
|
55
|
+
|
56
|
+
GlooLang::Exec::Dispatch.message 'run', o
|
57
|
+
end
|
58
|
+
|
59
|
+
# ---------------------------------------------------------------------
|
60
|
+
# Children
|
61
|
+
# ---------------------------------------------------------------------
|
62
|
+
|
63
|
+
#
|
64
|
+
# Does this object have children to add when an object
|
65
|
+
# is created in interactive mode?
|
66
|
+
# This does not apply during obj load, etc.
|
67
|
+
#
|
68
|
+
def add_children_on_create?
|
69
|
+
return true
|
70
|
+
end
|
71
|
+
|
72
|
+
#
|
73
|
+
# Add children to this object.
|
74
|
+
# This is used by containers to add children needed
|
75
|
+
# for default configurations.
|
76
|
+
#
|
77
|
+
def add_default_children
|
78
|
+
fac = $engine.factory
|
79
|
+
fac.create_string WORD, '', self
|
80
|
+
fac.create_string IN, '', self
|
81
|
+
fac.create_script DO, '', self
|
82
|
+
end
|
83
|
+
|
84
|
+
# ---------------------------------------------------------------------
|
85
|
+
# Messages
|
86
|
+
# ---------------------------------------------------------------------
|
87
|
+
|
88
|
+
#
|
89
|
+
# Get a list of message names that this object receives.
|
90
|
+
#
|
91
|
+
def self.messages
|
92
|
+
return super + [ 'run' ]
|
93
|
+
end
|
94
|
+
|
95
|
+
# Run the system command.
|
96
|
+
def msg_run
|
97
|
+
if each_child?
|
98
|
+
run_each_child
|
99
|
+
elsif each_word?
|
100
|
+
run_each_word
|
101
|
+
elsif each_line?
|
102
|
+
run_each_line
|
103
|
+
elsif each_repo?
|
104
|
+
run_each_repo
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# ---------------------------------------------------------------------
|
109
|
+
# Child Object
|
110
|
+
# ---------------------------------------------------------------------
|
111
|
+
|
112
|
+
#
|
113
|
+
# Is it set up to run for each word?
|
114
|
+
# If there is a child object by the name "word"
|
115
|
+
# then we will loop for each word in the string.
|
116
|
+
#
|
117
|
+
def each_child?
|
118
|
+
return true if contains_child? CHILD
|
119
|
+
|
120
|
+
return false
|
121
|
+
end
|
122
|
+
|
123
|
+
#
|
124
|
+
# Run for each word.
|
125
|
+
#
|
126
|
+
def run_each_child
|
127
|
+
o = find_child IN
|
128
|
+
return unless o
|
129
|
+
|
130
|
+
o = GlooLang::Objs::Alias.resolve_alias( o )
|
131
|
+
o.children.each do |child|
|
132
|
+
set_child child
|
133
|
+
run_do
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
#
|
138
|
+
# Set the child alias.
|
139
|
+
#
|
140
|
+
def set_child( obj )
|
141
|
+
o = find_child CHILD
|
142
|
+
return unless o
|
143
|
+
|
144
|
+
o.set_value obj.pn
|
145
|
+
end
|
146
|
+
|
147
|
+
# ---------------------------------------------------------------------
|
148
|
+
# Word
|
149
|
+
# ---------------------------------------------------------------------
|
150
|
+
|
151
|
+
#
|
152
|
+
# Is it set up to run for each word?
|
153
|
+
# If there is a child object by the name "word"
|
154
|
+
# then we will loop for each word in the string.
|
155
|
+
#
|
156
|
+
def each_word?
|
157
|
+
return true if find_child WORD
|
158
|
+
|
159
|
+
return false
|
160
|
+
end
|
161
|
+
|
162
|
+
#
|
163
|
+
# Run for each word.
|
164
|
+
#
|
165
|
+
def run_each_word
|
166
|
+
str = in_value
|
167
|
+
return unless str
|
168
|
+
|
169
|
+
str.split( ' ' ).each do |word|
|
170
|
+
set_word word
|
171
|
+
run_do
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
#
|
176
|
+
# Set the value of the word.
|
177
|
+
#
|
178
|
+
def set_word( word )
|
179
|
+
o = find_child WORD
|
180
|
+
return unless o
|
181
|
+
|
182
|
+
o.set_value word
|
183
|
+
end
|
184
|
+
|
185
|
+
# ---------------------------------------------------------------------
|
186
|
+
# Line
|
187
|
+
# ---------------------------------------------------------------------
|
188
|
+
|
189
|
+
#
|
190
|
+
# Is it set up to run for each line?
|
191
|
+
# If there is a child object by the name "line"
|
192
|
+
# then we will loop for each line in the string.
|
193
|
+
#
|
194
|
+
def each_line?
|
195
|
+
return true if find_child LINE
|
196
|
+
|
197
|
+
return false
|
198
|
+
end
|
199
|
+
|
200
|
+
#
|
201
|
+
# Run for each line.
|
202
|
+
#
|
203
|
+
def run_each_line
|
204
|
+
str = in_value
|
205
|
+
return unless str
|
206
|
+
|
207
|
+
str.each_line do |line|
|
208
|
+
set_line line
|
209
|
+
run_do
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
#
|
214
|
+
# Set the value of the word.
|
215
|
+
#
|
216
|
+
def set_line( line )
|
217
|
+
o = find_child LINE
|
218
|
+
return unless o
|
219
|
+
|
220
|
+
o.set_value line
|
221
|
+
end
|
222
|
+
|
223
|
+
# ---------------------------------------------------------------------
|
224
|
+
# Git Repo
|
225
|
+
# ---------------------------------------------------------------------
|
226
|
+
|
227
|
+
#
|
228
|
+
# Is it set up to run for each git repo?
|
229
|
+
# If there is a child object by the name "repo"
|
230
|
+
# then we will loop for each repo in the directory.
|
231
|
+
#
|
232
|
+
def each_repo?
|
233
|
+
return true if find_child REPO
|
234
|
+
|
235
|
+
return false
|
236
|
+
end
|
237
|
+
|
238
|
+
#
|
239
|
+
# Find all git projects in a path.
|
240
|
+
#
|
241
|
+
def find_all_git_projects( path )
|
242
|
+
path.children.collect do |f|
|
243
|
+
if f.directory? && ( File.basename( f ) == '.git' )
|
244
|
+
File.dirname( f )
|
245
|
+
elsif f.directory?
|
246
|
+
find_all_git_projects( f )
|
247
|
+
end
|
248
|
+
end.flatten.compact
|
249
|
+
end
|
250
|
+
|
251
|
+
#
|
252
|
+
# Run for each line.
|
253
|
+
#
|
254
|
+
def run_each_repo
|
255
|
+
path = in_value
|
256
|
+
return unless path
|
257
|
+
|
258
|
+
path = Pathname.new( path )
|
259
|
+
repos = find_all_git_projects( path )
|
260
|
+
repos.each do |o|
|
261
|
+
set_repo o
|
262
|
+
run_do
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
#
|
267
|
+
# Set the value of the repo.
|
268
|
+
# This is a path to the repo.
|
269
|
+
#
|
270
|
+
def set_repo( path )
|
271
|
+
o = find_child REPO
|
272
|
+
return unless o
|
273
|
+
|
274
|
+
o.set_value path
|
275
|
+
end
|
276
|
+
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# A looping construct...do something x times.
|
5
|
+
#
|
6
|
+
|
7
|
+
module GlooLang
|
8
|
+
module Objs
|
9
|
+
class Repeat < GlooLang::Core::Obj
|
10
|
+
|
11
|
+
KEYWORD = 'repeat'.freeze
|
12
|
+
KEYWORD_SHORT = 'repeat'.freeze
|
13
|
+
TIMES = 'times'.freeze
|
14
|
+
INDEX = 'index'.freeze
|
15
|
+
DO = 'do'.freeze
|
16
|
+
|
17
|
+
#
|
18
|
+
# The name of the object type.
|
19
|
+
#
|
20
|
+
def self.typename
|
21
|
+
return KEYWORD
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# The short name of the object type.
|
26
|
+
#
|
27
|
+
def self.short_typename
|
28
|
+
return KEYWORD_SHORT
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Get the URI from the child object.
|
33
|
+
# Returns nil if there is none.
|
34
|
+
#
|
35
|
+
def times
|
36
|
+
o = find_child TIMES
|
37
|
+
return o ? o.value : 0
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Run the do script once.
|
42
|
+
#
|
43
|
+
def run_do
|
44
|
+
o = find_child DO
|
45
|
+
return unless o
|
46
|
+
|
47
|
+
GlooLang::Exec::Dispatch.message 'run', o
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# Set the index of the current iteration.
|
52
|
+
#
|
53
|
+
def set_index( index )
|
54
|
+
o = find_child INDEX
|
55
|
+
return unless o
|
56
|
+
|
57
|
+
o.set_value index
|
58
|
+
end
|
59
|
+
|
60
|
+
# ---------------------------------------------------------------------
|
61
|
+
# Children
|
62
|
+
# ---------------------------------------------------------------------
|
63
|
+
|
64
|
+
#
|
65
|
+
# Does this object have children to add when an object
|
66
|
+
# is created in interactive mode?
|
67
|
+
# This does not apply during obj load, etc.
|
68
|
+
#
|
69
|
+
def add_children_on_create?
|
70
|
+
return true
|
71
|
+
end
|
72
|
+
|
73
|
+
#
|
74
|
+
# Add children to this object.
|
75
|
+
# This is used by containers to add children needed
|
76
|
+
# for default configurations.
|
77
|
+
#
|
78
|
+
def add_default_children
|
79
|
+
fac = $engine.factory
|
80
|
+
fac.create_int TIMES, 0, self
|
81
|
+
fac.create_int INDEX, 0, self
|
82
|
+
fac.create_script DO, '', self
|
83
|
+
end
|
84
|
+
|
85
|
+
# ---------------------------------------------------------------------
|
86
|
+
# Messages
|
87
|
+
# ---------------------------------------------------------------------
|
88
|
+
|
89
|
+
#
|
90
|
+
# Get a list of message names that this object receives.
|
91
|
+
#
|
92
|
+
def self.messages
|
93
|
+
return super + [ 'run' ]
|
94
|
+
end
|
95
|
+
|
96
|
+
#
|
97
|
+
# Run the repeat loop.
|
98
|
+
#
|
99
|
+
def msg_run
|
100
|
+
times.times do |index|
|
101
|
+
set_index index
|
102
|
+
run_do
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# Markdown data.
|
5
|
+
#
|
6
|
+
|
7
|
+
module GlooLang
|
8
|
+
module Objs
|
9
|
+
class Markdown < GlooLang::Core::Obj
|
10
|
+
|
11
|
+
KEYWORD = 'markdown'.freeze
|
12
|
+
KEYWORD_SHORT = 'md'.freeze
|
13
|
+
|
14
|
+
#
|
15
|
+
# The name of the object type.
|
16
|
+
#
|
17
|
+
def self.typename
|
18
|
+
return KEYWORD
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# The short name of the object type.
|
23
|
+
#
|
24
|
+
def self.short_typename
|
25
|
+
return KEYWORD_SHORT
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Set the value with any necessary type conversions.
|
30
|
+
#
|
31
|
+
def set_value( new_value )
|
32
|
+
self.value = new_value.to_s
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Does this object support multi-line values?
|
37
|
+
# Initially only true for scripts.
|
38
|
+
#
|
39
|
+
def multiline_value?
|
40
|
+
return false
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Get the number of lines of text.
|
45
|
+
#
|
46
|
+
def line_count
|
47
|
+
return value.split( "\n" ).count
|
48
|
+
end
|
49
|
+
|
50
|
+
# ---------------------------------------------------------------------
|
51
|
+
# Messages
|
52
|
+
# ---------------------------------------------------------------------
|
53
|
+
|
54
|
+
#
|
55
|
+
# Get a list of message names that this object receives.
|
56
|
+
#
|
57
|
+
def self.messages
|
58
|
+
return super + %w[show page]
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# Show the markdown data in the terminal.
|
63
|
+
#
|
64
|
+
def msg_show
|
65
|
+
$engine.platform.show( self.value, true, false )
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# Show the markdown data in the terminal, paginated.
|
70
|
+
#
|
71
|
+
def msg_page
|
72
|
+
return unless self.value
|
73
|
+
|
74
|
+
$engine.platform.show( md, true, true )
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# A MySQL database connection.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# https://github.com/brianmario/mysql2
|
8
|
+
# https://www.rubydoc.info/gems/mysql2/0.2.3/Mysql2/Client
|
9
|
+
#
|
10
|
+
# Connection Parameters
|
11
|
+
# user = opts[:username]
|
12
|
+
# pass = opts[:password]
|
13
|
+
# host = opts[:host] || 'localhost'
|
14
|
+
# port = opts[:port] || 3306
|
15
|
+
# database = opts[:database]
|
16
|
+
# socket = opts[:socket]
|
17
|
+
# flags = opts[:flags] || 0
|
18
|
+
#
|
19
|
+
require 'mysql2'
|
20
|
+
|
21
|
+
module GlooLang
|
22
|
+
module Objs
|
23
|
+
class Mysql < GlooLang::Core::Obj
|
24
|
+
|
25
|
+
KEYWORD = 'mysql'.freeze
|
26
|
+
KEYWORD_SHORT = 'mysql'.freeze
|
27
|
+
|
28
|
+
HOST = 'host'.freeze
|
29
|
+
DB = 'database'.freeze
|
30
|
+
USER = 'username'.freeze
|
31
|
+
PASSWD = 'password'.freeze
|
32
|
+
|
33
|
+
#
|
34
|
+
# The name of the object type.
|
35
|
+
#
|
36
|
+
def self.typename
|
37
|
+
return KEYWORD
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# The short name of the object type.
|
42
|
+
#
|
43
|
+
def self.short_typename
|
44
|
+
return KEYWORD_SHORT
|
45
|
+
end
|
46
|
+
|
47
|
+
# ---------------------------------------------------------------------
|
48
|
+
# Children
|
49
|
+
# ---------------------------------------------------------------------
|
50
|
+
|
51
|
+
#
|
52
|
+
# Does this object have children to add when an object
|
53
|
+
# is created in interactive mode?
|
54
|
+
# This does not apply during obj load, etc.
|
55
|
+
#
|
56
|
+
def add_children_on_create?
|
57
|
+
return true
|
58
|
+
end
|
59
|
+
|
60
|
+
#
|
61
|
+
# Add children to this object.
|
62
|
+
# This is used by containers to add children needed
|
63
|
+
# for default configurations.
|
64
|
+
#
|
65
|
+
def add_default_children
|
66
|
+
fac = $engine.factory
|
67
|
+
fac.create_string HOST, nil, self
|
68
|
+
fac.create_string DB, nil, self
|
69
|
+
fac.create_string USER, nil, self
|
70
|
+
fac.create_string PASSWD, nil, self
|
71
|
+
end
|
72
|
+
|
73
|
+
# ---------------------------------------------------------------------
|
74
|
+
# Messages
|
75
|
+
# ---------------------------------------------------------------------
|
76
|
+
|
77
|
+
#
|
78
|
+
# Get a list of message names that this object receives.
|
79
|
+
#
|
80
|
+
def self.messages
|
81
|
+
return super + [ 'verify' ]
|
82
|
+
end
|
83
|
+
|
84
|
+
#
|
85
|
+
# SSH to the host and execute the command, then update result.
|
86
|
+
#
|
87
|
+
def msg_verify
|
88
|
+
return unless connects?
|
89
|
+
|
90
|
+
$engine.heap.it.set_to true
|
91
|
+
end
|
92
|
+
|
93
|
+
# ---------------------------------------------------------------------
|
94
|
+
# DB functions (all database connections)
|
95
|
+
# ---------------------------------------------------------------------
|
96
|
+
|
97
|
+
#
|
98
|
+
# Open a connection and execute the SQL statement.
|
99
|
+
# Return the resulting data.
|
100
|
+
#
|
101
|
+
def query( sql, params = nil )
|
102
|
+
h = {
|
103
|
+
host: host_value,
|
104
|
+
database: db_value,
|
105
|
+
username: user_value,
|
106
|
+
password: passwd_value
|
107
|
+
}
|
108
|
+
client = Mysql2::Client.new( h )
|
109
|
+
return client.query( sql ) unless params
|
110
|
+
|
111
|
+
pst = client.prepare( sql )
|
112
|
+
return pst.execute( *params )
|
113
|
+
end
|
114
|
+
|
115
|
+
# ---------------------------------------------------------------------
|
116
|
+
# Private functions
|
117
|
+
# ---------------------------------------------------------------------
|
118
|
+
|
119
|
+
private
|
120
|
+
|
121
|
+
#
|
122
|
+
# Get the host from the child object.
|
123
|
+
# Returns nil if there is none.
|
124
|
+
#
|
125
|
+
def host_value
|
126
|
+
o = find_child HOST
|
127
|
+
return nil unless o
|
128
|
+
|
129
|
+
o = GlooLang::Objs::Alias.resolve_alias( o )
|
130
|
+
return o.value
|
131
|
+
end
|
132
|
+
|
133
|
+
#
|
134
|
+
# Get the Database name from the child object.
|
135
|
+
# Returns nil if there is none.
|
136
|
+
#
|
137
|
+
def db_value
|
138
|
+
o = find_child DB
|
139
|
+
return nil unless o
|
140
|
+
|
141
|
+
o = GlooLang::Objs::Alias.resolve_alias( o )
|
142
|
+
return o.value
|
143
|
+
end
|
144
|
+
|
145
|
+
#
|
146
|
+
# Get the Username from the child object.
|
147
|
+
# Returns nil if there is none.
|
148
|
+
#
|
149
|
+
def user_value
|
150
|
+
o = find_child USER
|
151
|
+
return nil unless o
|
152
|
+
|
153
|
+
o = GlooLang::Objs::Alias.resolve_alias( o )
|
154
|
+
return o.value
|
155
|
+
end
|
156
|
+
|
157
|
+
#
|
158
|
+
# Get the Password name from the child object.
|
159
|
+
# Returns nil if there is none.
|
160
|
+
#
|
161
|
+
def passwd_value
|
162
|
+
o = find_child PASSWD
|
163
|
+
return nil unless o
|
164
|
+
|
165
|
+
o = GlooLang::Objs::Alias.resolve_alias( o )
|
166
|
+
return o.value
|
167
|
+
end
|
168
|
+
|
169
|
+
#
|
170
|
+
# Try the connection and make sure it works.
|
171
|
+
# Returns true if we can establish a connection.
|
172
|
+
#
|
173
|
+
def connects?
|
174
|
+
begin
|
175
|
+
h = {
|
176
|
+
host: host_value,
|
177
|
+
database: db_value,
|
178
|
+
username: user_value,
|
179
|
+
password: passwd_value
|
180
|
+
}
|
181
|
+
Mysql2::Client.new( h )
|
182
|
+
rescue => e
|
183
|
+
$engine.err e.message
|
184
|
+
$engine.heap.it.set_to false
|
185
|
+
return false
|
186
|
+
end
|
187
|
+
return true
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|