gloo 4.6.1 → 5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/gloo.gemspec +22 -11
  4. data/lib/VERSION +1 -1
  5. data/lib/VERSION_NOTES +12 -0
  6. data/lib/gloo/app/engine.rb +8 -1
  7. data/lib/gloo/app/running_app.rb +13 -0
  8. data/lib/gloo/app/settings.rb +5 -1
  9. data/lib/gloo/core/dictionary.rb +15 -2
  10. data/lib/gloo/objs/ctrl/each.rb +2 -2
  11. data/lib/gloo/plugin/base.rb +19 -0
  12. data/lib/gloo/plugin/callback.rb +33 -0
  13. data/lib/gloo/plugin/ext_manager.rb +90 -0
  14. data/lib/gloo/plugin/lib_manager.rb +97 -0
  15. data/lib/gloo/verbs/exists.rb +75 -0
  16. data/lib/gloo/verbs/help.rb +58 -1
  17. data/lib/gloo/verbs/load.rb +49 -5
  18. data/lib/gloo/verbs/redirect.rb +2 -1
  19. metadata +38 -166
  20. data/lib/gloo/objs/cli/colorize.rb +0 -73
  21. data/lib/gloo/objs/cli/confirm.rb +0 -96
  22. data/lib/gloo/objs/cli/menu.rb +0 -370
  23. data/lib/gloo/objs/cli/menu_item.rb +0 -95
  24. data/lib/gloo/objs/cli/prompt.rb +0 -110
  25. data/lib/gloo/objs/cli/select.rb +0 -127
  26. data/lib/gloo/objs/ctrl/each_repo.rb +0 -84
  27. data/lib/gloo/objs/data/markdown.rb +0 -133
  28. data/lib/gloo/objs/data/markdown_ext.rb +0 -260
  29. data/lib/gloo/objs/data/mysql.rb +0 -254
  30. data/lib/gloo/objs/data/pg.rb +0 -216
  31. data/lib/gloo/objs/data/query.rb +0 -269
  32. data/lib/gloo/objs/data/query_result.rb +0 -158
  33. data/lib/gloo/objs/data/sqlite.rb +0 -174
  34. data/lib/gloo/objs/data/table.rb +0 -267
  35. data/lib/gloo/objs/dev/git.rb +0 -140
  36. data/lib/gloo/objs/dev/stats.rb +0 -123
  37. data/lib/gloo/objs/system/ssh_exec.rb +0 -126
  38. data/lib/gloo/objs/web/slack.rb +0 -130
  39. data/lib/gloo/objs/web/teams.rb +0 -117
  40. data/lib/gloo/objs/web_svr/element.rb +0 -254
  41. data/lib/gloo/objs/web_svr/field.rb +0 -429
  42. data/lib/gloo/objs/web_svr/form.rb +0 -271
  43. data/lib/gloo/objs/web_svr/page.rb +0 -562
  44. data/lib/gloo/objs/web_svr/partial.rb +0 -210
  45. data/lib/gloo/objs/web_svr/svr.rb +0 -713
  46. data/lib/gloo/utils/stats.rb +0 -206
  47. data/lib/gloo/verbs/alert.rb +0 -79
  48. data/lib/gloo/verbs/beep.rb +0 -40
  49. data/lib/gloo/web_svr/asset.rb +0 -407
  50. data/lib/gloo/web_svr/asset_info.rb +0 -116
  51. data/lib/gloo/web_svr/config.rb +0 -56
  52. data/lib/gloo/web_svr/embedded_renderer.rb +0 -154
  53. data/lib/gloo/web_svr/handler.rb +0 -154
  54. data/lib/gloo/web_svr/request.rb +0 -143
  55. data/lib/gloo/web_svr/request_params.rb +0 -181
  56. data/lib/gloo/web_svr/response.rb +0 -177
  57. data/lib/gloo/web_svr/response_code.rb +0 -69
  58. data/lib/gloo/web_svr/routing/resource_router.rb +0 -47
  59. data/lib/gloo/web_svr/routing/router.rb +0 -232
  60. data/lib/gloo/web_svr/routing/show_routes.rb +0 -94
  61. data/lib/gloo/web_svr/server.rb +0 -105
  62. data/lib/gloo/web_svr/session.rb +0 -215
  63. data/lib/gloo/web_svr/table_renderer.rb +0 -151
  64. data/lib/gloo/web_svr/web_method.rb +0 -54
  65. /data/lib/gloo/objs/{security → str_utils}/cipher.rb +0 -0
  66. /data/lib/gloo/objs/{security → str_utils}/csrf_token.rb +0 -0
  67. /data/lib/gloo/objs/{security → str_utils}/password.rb +0 -0
  68. /data/lib/gloo/objs/{ror → system}/erb.rb +0 -0
  69. /data/lib/gloo/objs/{ror → system}/eval.rb +0 -0
@@ -1,269 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
- #
4
- # A SQL database query.
5
- # Relies on a database connection object.
6
- #
7
-
8
- module Gloo
9
- module Objs
10
- class Query < Gloo::Core::Obj
11
-
12
- KEYWORD = 'query'.freeze
13
- KEYWORD_SHORT = 'sql'.freeze
14
-
15
- DB = 'database'.freeze
16
- SQL = 'sql'.freeze
17
- RESULT = 'result'.freeze
18
- PARAMS = 'params'.freeze
19
- SIMPLE_LIST = 'simple_list'.freeze
20
-
21
- DB_MISSING_ERR = 'The database connection is missing!'.freeze
22
-
23
- #
24
- # The name of the object type.
25
- #
26
- def self.typename
27
- return KEYWORD
28
- end
29
-
30
- #
31
- # The short name of the object type.
32
- #
33
- def self.short_typename
34
- return KEYWORD_SHORT
35
- end
36
-
37
- #
38
- # Get the result container if it exists.
39
- #
40
- def get_result_can
41
- result_can = find_child RESULT
42
- result_can = Gloo::Objs::Alias.resolve_alias( @engine, result_can )
43
- return result_can
44
- end
45
-
46
- # ---------------------------------------------------------------------
47
- # Children
48
- # ---------------------------------------------------------------------
49
-
50
- #
51
- # Does this object have children to add when an object
52
- # is created in interactive mode?
53
- # This does not apply during obj load, etc.
54
- #
55
- def add_children_on_create?
56
- return true
57
- end
58
-
59
- #
60
- # Add children to this object.
61
- # This is used by containers to add children needed
62
- # for default configurations.
63
- #
64
- def add_default_children
65
- fac = @engine.factory
66
- fac.create_alias DB, nil, self
67
- fac.create_string SQL, nil, self
68
- fac.create_can RESULT, self
69
- end
70
-
71
- # ---------------------------------------------------------------------
72
- # Messages
73
- # ---------------------------------------------------------------------
74
-
75
- #
76
- # Get a list of message names that this object receives.
77
- #
78
- def self.messages
79
- return super + [ 'run' ]
80
- end
81
-
82
- #
83
- # Run the query and process the results.
84
- #
85
- def msg_run
86
- db = db_obj
87
- return unless db
88
-
89
- begin
90
- clear_results
91
-
92
- log_query sql_value, param_array
93
- result = db.query( sql_value, param_array )
94
- process_result( result, db )
95
- rescue => e
96
- @engine.log_exception e
97
- return
98
- end
99
- end
100
-
101
- #
102
- # Run the query and return the results.
103
- #
104
- def run_query
105
- db = db_obj
106
- return unless db
107
-
108
- begin
109
- log_query sql_value, param_array
110
-
111
- db_start = ::Time.now
112
- result = db.query( sql_value, param_array )
113
- db_done = ::Time.now
114
- elapsed = ( ( db_done - db_start ) * 1000.0 ).round(2)
115
-
116
- app = @engine.running_app
117
- app.add_db_time elapsed if app
118
- return result
119
- rescue => e
120
- @engine.log_exception e
121
- return
122
- end
123
- end
124
-
125
- #
126
- # Write the query to the log.
127
- #
128
- def log_query sql, params
129
- @engine.log.info "SQL PARAMS: #{params}" if params
130
- @engine.log.info "SQL: #{sql}"
131
- end
132
-
133
-
134
- # ---------------------------------------------------------------------
135
- # Output as simple list
136
- # ---------------------------------------------------------------------
137
-
138
- #
139
- # Should the output be put in a simple list?
140
- #
141
- def simple_list?
142
- o = find_child SIMPLE_LIST
143
- return false unless o
144
-
145
- return o.value
146
- end
147
-
148
-
149
- # ---------------------------------------------------------------------
150
- # Private functions
151
- # ---------------------------------------------------------------------
152
-
153
- private
154
-
155
- #
156
- # Get the database connection.
157
- #
158
- def db_obj
159
- o = find_child DB
160
-
161
- unless o
162
- @engine.err DB_MISSING_ERR
163
- return nil
164
- end
165
-
166
- return Gloo::Objs::Alias.resolve_alias( @engine, o )
167
- end
168
-
169
- #
170
- # Get the SQL from the child object.
171
- # Returns nil if there is none.
172
- #
173
- def sql_value
174
- o = find_child SQL
175
- return nil unless o
176
-
177
- o = Gloo::Objs::Alias.resolve_alias( @engine, o )
178
- return o.value
179
- end
180
-
181
- #
182
- # Do something with the result of the SQL Query call.
183
- # If there's a result container, we'll create objects in it.
184
- # If not, we'll just show the output in the console.
185
- #
186
- def process_result( result, db )
187
- return if result.nil?
188
-
189
- query_result = db.get_query_result( result )
190
- return unless query_result
191
- return unless query_result.has_data_to_show?
192
-
193
- result_can = get_result_can
194
-
195
- if result_can
196
- if simple_list?
197
- query_result.update_result_container_simple result_can
198
- else
199
- query_result.update_result_container result_can
200
- end
201
- else
202
- query_result.show
203
- end
204
- end
205
-
206
- #
207
- # Get the array of parameters.
208
- # If there is no PARAM container of if it is empty,
209
- # we'll return a nil value.
210
- #
211
- def param_array
212
- o = find_child PARAMS
213
- return nil unless o
214
-
215
- return nil if o.child_count.zero?
216
-
217
- params = []
218
- o.children.each do |p|
219
- p = Gloo::Objs::Alias.resolve_alias( @engine, p )
220
- params << p.sql_value
221
- end
222
-
223
- return params
224
- end
225
-
226
- #
227
- # Clear out results container.
228
- # Prevents data from the last use being used in this
229
- # one if no data was found.
230
- #
231
- def clear_results
232
- result_can = get_result_can
233
- return unless result_can
234
- return unless result_can.child_count.positive?
235
-
236
- if result_is_values?
237
- clear_values
238
- else
239
- get_result_can.delete_children
240
- end
241
- end
242
-
243
- #
244
- # Is the result container a list of values?
245
- # If not it is a list of rows.
246
- #
247
- def result_is_values?
248
- first_child = get_result_can.children.first
249
-
250
- if first_child && first_child&.is_container?
251
- return false
252
- end
253
-
254
- return true
255
- end
256
-
257
- #
258
- # Clear out the values in the results container.
259
- #
260
- def clear_values
261
- get_result_can.children.each do |c|
262
- c = Gloo::Objs::Alias.resolve_alias( @engine, c )
263
- c.value = nil
264
- end
265
- end
266
-
267
- end
268
- end
269
- end
@@ -1,158 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2022 Eric Crane. All rights reserved.
3
- #
4
- # The result of a SQL database query.
5
- #
6
-
7
- module Gloo
8
- module Objs
9
- class QueryResult
10
-
11
- DB = 'database'.freeze
12
- SQL = 'sql'.freeze
13
- RESULT = 'result'.freeze
14
- PARAMS = 'params'.freeze
15
-
16
-
17
- # ---------------------------------------------------------------------
18
- # Set up the Result
19
- # ---------------------------------------------------------------------
20
-
21
- #
22
- # Create the Result object
23
- def initialize( heads, data, engine=nil )
24
- @heads = heads
25
- @data = data
26
- @engine = engine
27
- end
28
-
29
-
30
- # ---------------------------------------------------------------------
31
- # Helper Functions
32
- # ---------------------------------------------------------------------
33
-
34
- #
35
- # Does the data contain a single row?
36
- # OR, if the result is empty, return false.
37
- #
38
- def single_row_result?
39
- if @result_can && ( @result_can.child_count == 0 )
40
- return false
41
- end
42
-
43
- return @data.count == 1
44
- end
45
-
46
- #
47
- # Does this query result have data to show?
48
- #
49
- def has_data_to_show?
50
- return false unless @heads
51
- return false unless @data
52
- return false if @heads.count == 0
53
- return false if @data.count == 0
54
-
55
- return true
56
- end
57
-
58
-
59
- # ---------------------------------------------------------------------
60
- # Show Results
61
- # ---------------------------------------------------------------------
62
-
63
- #
64
- # Show the result of the query
65
- #
66
- def show
67
- single_row_result? ? show_single_row : show_rows
68
- end
69
-
70
- #
71
- # Show a single row in a vertical, form style view.
72
- #
73
- def show_single_row
74
- arr = []
75
- row = @data[0]
76
- @heads.each_with_index do |h, i|
77
- arr << [ h, row[i] ]
78
- end
79
- @engine.platform.table.show [ 'Field', 'Value' ], arr
80
- end
81
-
82
- #
83
- # Show multiple rows in a table view.
84
- #
85
- def show_rows
86
- @engine.platform.table.show @heads, @data
87
- end
88
-
89
- # ---------------------------------------------------------------------
90
- # Update results in object(s)
91
- # ---------------------------------------------------------------------
92
-
93
- #
94
- # Update the result container with the data from the query.
95
- #
96
- def update_result_container( in_can )
97
- @result_can = in_can
98
- single_row_result? ? update_single_row : update_rows
99
- end
100
-
101
- #
102
- # Update the result container with the data from the query.
103
- #
104
- def update_result_container_simple( in_can )
105
- @result_can = in_can
106
- single_row_result? ? update_single_row : update_rows_simple
107
- end
108
-
109
- #
110
- # The result has a single row.
111
- # Map values from the result set to objects that are present.
112
- #
113
- def update_single_row
114
- row = @data[0]
115
- @heads.each_with_index do |h, i|
116
- child = @result_can.find_child h
117
- child = Gloo::Objs::Alias.resolve_alias( @engine, child )
118
- child.set_value row[i] if child
119
- end
120
- end
121
-
122
- #
123
- # Put all rows in the result object.
124
- #
125
- def update_rows
126
- @data.each_with_index do |row, i|
127
- can = @result_can.find_add_child( i.to_s, 'can' )
128
- row.each_with_index do |v, i|
129
- o = can.find_add_child( @heads[i], 'untyped' )
130
- o.set_value v
131
- end
132
- end
133
- end
134
-
135
- #
136
- # Put all rows in the result object.
137
- #
138
- def update_rows_simple
139
- @data.each do |row|
140
- row.each do |val|
141
- o = @result_can.find_add_child( val, 'untyped' )
142
- o.set_value val
143
- end
144
- end
145
- end
146
-
147
-
148
- # ---------------------------------------------------------------------
149
- # Private functions
150
- # ---------------------------------------------------------------------
151
-
152
- private
153
-
154
-
155
-
156
- end
157
- end
158
- end
@@ -1,174 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
- #
4
- # A Sqlite3 database connection.
5
- #
6
- # https://www.rubydoc.info/gems/sqlite3/1.3.11
7
- # https://www.devdungeon.com/content/ruby-sqlite-tutorial
8
- #
9
- # db.results_as_hash = true
10
- # Set results to return as Hash object.
11
- # This is slower but offers a huge convenience.
12
- # Consider turning it off for high performance situations.
13
- # Each row will have the column name as the hash key.
14
- #
15
- # # Alternatively, to only get one row and discard the rest,
16
- # replace `db.query()` with `db.get_first_value()`.
17
- #
18
- require 'sqlite3'
19
-
20
- module Gloo
21
- module Objs
22
- class Sqlite < Gloo::Core::Obj
23
-
24
- KEYWORD = 'sqlite'.freeze
25
- KEYWORD_SHORT = 'sqlite'.freeze
26
-
27
- DB = 'database'.freeze
28
- DEFAULT_DB = 'test.db'.freeze
29
-
30
- DB_REQUIRED_ERR = 'The database name is required!'.freeze
31
- DB_NOT_FOUND_ERR = 'The database file was not found!'.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 DB, DEFAULT_DB, self
68
- end
69
-
70
- # ---------------------------------------------------------------------
71
- # Messages
72
- # ---------------------------------------------------------------------
73
-
74
- #
75
- # Get a list of message names that this object receives.
76
- #
77
- def self.messages
78
- return super + [ 'verify' ]
79
- end
80
-
81
- #
82
- # Verify access to the Sqlite database specified.
83
- #
84
- def msg_verify
85
- name = db_value
86
- if name.empty?
87
- @engine.err DB_REQUIRED_ERR
88
- @engine.heap.it.set_to false
89
- return
90
- end
91
-
92
- unless File.exist? name
93
- @engine.err DB_NOT_FOUND_ERR
94
- @engine.heap.it.set_to false
95
- return
96
- end
97
-
98
- return unless connects?
99
-
100
- @engine.heap.it.set_to true
101
- end
102
-
103
- # ---------------------------------------------------------------------
104
- # DB functions (all database connections)
105
- # ---------------------------------------------------------------------
106
-
107
- #
108
- # Open a connection and execute the SQL statement.
109
- # Return the resulting data.
110
- #
111
- def query( sql, params = nil )
112
- name = db_value
113
- unless name
114
- @engine.err DB_REQUIRED_ERR
115
- return
116
- end
117
-
118
- db = SQLite3::Database.open name
119
- # db.results_as_hash = true
120
- results = db.query( sql, params )
121
-
122
- return results
123
- end
124
-
125
- #
126
- # Based on the result set, build a QueryResult object.
127
- #
128
- def get_query_result( result )
129
- rows = []
130
- while ( row = result.next ) do
131
- rows << row
132
- end
133
-
134
- return QueryResult.new( result.columns, rows )
135
- end
136
-
137
-
138
- # ---------------------------------------------------------------------
139
- # Private functions
140
- # ---------------------------------------------------------------------
141
-
142
- private
143
-
144
- #
145
- # Get the Database file from the child object.
146
- # Returns nil if there is none.
147
- #
148
- def db_value
149
- o = find_child DB
150
- return nil unless o
151
-
152
- return o.value
153
- end
154
-
155
- #
156
- # Try the connection and make sure it works.
157
- # Returns true if we can connect and do a query.
158
- #
159
- def connects?
160
- begin
161
- db = SQLite3::Database.open db_value
162
- sql = "SELECT COUNT(name) FROM sqlite_master WHERE type='table'"
163
- db.get_first_value sql
164
- rescue => e
165
- @engine.log_exception e
166
- @engine.heap.it.set_to false
167
- return false
168
- end
169
- return true
170
- end
171
-
172
- end
173
- end
174
- end